How to add radio button as mandatory field to register

How can I add a radio button as mandatory field when user is registering (with three choices to be specific)?

I first tried to gather this information through vendor mandatory attribute but the problem is that the user can register login to service (and send messages to to listings) without having to include this mandatory information as currently it’s only mandatory when the user tries to submit a listing (but not all user types needs to do this). (I have accepted the vendor direct registration setting also which I thought would directly force every user registering to first add mandatory vendor information specified as mandatory vendor attribute).

So in essence what I try to accomplish is to get the information from the user before he can use the logged in functionalities is to specify which user type he is (User type 1, User type 2 or User type 3) which I will use as a parameter in further functionality down the road. Thank you for your help.

Hi,

Unfortunately, this is not possible, it will require a custom implementation. Please check this sample PHP snippet: Add a custom checkbox to the user registration form #hivepress #users · GitHub

​I hope this is helpful to you.

Hi,

I’m trying to implement this as per your link that you provided but seems I can’t get it to work. I also checked Hivepress Developer Docs on radio buttons and forms and I thought I got it to work.

add_action(
	'hivepress/v1/models/user/register',
	function( $user_id, $values ) {
		if(isset($values['first_name'], $values['last_name'])){
			update_user_meta($user_id, 'first_name', $values['first_name']);
			update_user_meta($user_id, 'last_name', $values['last_name']);
			update_user_meta($user_id, 'hp_user_type', $values['hp_user_type']);
		}
	},
	10, 
	2
);

add_filter(
	'hivepress/v1/forms/user_register',
	function ( $args, $form ) {
		$args['fields'] = array_merge($args['fields'], [
			'first_name' => [
				'label' => 'First name',
				'type'    => 'text',
				'required' => true,
				'_order' => 1,
			],
			
			'last_name' => [
				'label' => 'Last name',
				'type'    => 'text',
				'required' => true,
				'_order' => 2,
			],
			
			'hp_user_type' => [
				'label' => 'User Type',
				'type'    => 'radio',
				'option' => [
					'user_type_1' => 'User Type 1',
					'user_type_2' => 'User Type 2',
					'user_type_3' => 'User Type 3',
				],
				'required' => true,
				'_order' => 3,
				
			],
			
			
		]);

		return $args;
	},
	10,
	2
);

With this first name and last name text boxes become visible in the registration form but user type radio buttons are not visible. Could you please guide me?

Screenshot 2024-07-03 102107

If these radio buttons are linked to a custom attribute this requires further customizations and debugging. I highly recommend waiting for the next HivePress update (it’s planned for tomorrow), there will be an option to add attributes to the registration form.