• Resolved den1sa

    (@den1sa)


    Hi everyone,

    In a standard webpage, I am trying to populate field 2 (animal_list) based on the initial selection in field 1 (animal_type). So if a user selects Wild from the dropdown (field 1), a list of wild animals appears in the animal_list field (field 2). If however they select Pets, then a list of pets appears in the same animal_list field. I can do this in an Ultimate Member form, but I cannot seem to achieve the same result in a standard webpage that I wish to use for registration.

    The problem I am having is with the duplicate animal_list field. When I use this the animal_list field does not populate as expected. I just want to filter the animal_list field based on the animal_type selection.

    Not sure what to do from here. Can anyone help me with this?

    <?php
    
    $fields[] = new PMProRH_Field(
    	'animal_type',				// input name, will also be used as meta key
    	'select',							// type of field
    	array(
    	'required'	=> true,				// make this field required
    	'profile'	=> false,				// do not only show in profile for admins
    	'levels'	=> array(7),	// only levels 11 and 12 should have the type field
    	'label'		=> 'What type of animal are you registering?',			// custom field label
    		'options' => array(				// <option> elements for select field
    			''		=> 'Please select animal type',				// blank option - cannot be selected if this field is required
    			'Wild'	=> 'Wild',	// <option value="3</option>
    			'Pets'	=> 'Pets',	// <option value="3</option>
    		)
    	)
    );	
    		 
    	$fields[] = new PMProRH_Field(
    	"animal_list", // input name, will also be used as meta key
    	"select", // type of field
    	array(
    	"options" => array(				// <option> elements for select field
    			''		=> 'Please select animal type',	// blank option - cannot be selected if this field is required
    							'Tiger'=>'Tiger',//<option value="1</option>
    							'Lion'=>'Lion',//<option value="1</option>
    							'Eagle'=>'Eagle',//<option value="1</option>
    		),
    	"label" => "Wild Animal Types",
    	"levels"	=> array(7),
    	"profile" => true,	
    	"required" => true,
    	"depends" => array(
    	array(
    	"id" => "animal_type", //depends on this field
    	"value" => "Wild" //if selected show this field
    	)
    	)
    	)
    	);	
    	 
    	$fields[] = new PMProRH_Field(
    	"animal_list", // input name, will also be used as meta key
    	"select", // type of field
    	array(
    	"options" => array(				// <option> elements for select field
    			''		=> 'Please select animal type',	// blank option - cannot be selected if this field is required
    			'Cat'=>'Cat',//<option value="1</option>
    			'Dog'=>'Dog',//<option value="1</option>
    			'Budgie'=>'Budgie',//<option value="1</option>
    		),
    	"label" => "Pet Types",
    	"levels"	=> array(7),
    	"profile" => true,	
    	"required" => true,
    	"depends" => array(
    	array(
    	"id" => "animal_type", //depends on this field
    	"value" => "Pets" //if selected show this field
    	)
    	)
    	)
    	);
    • This topic was modified 1 year, 7 months ago by den1sa.
    • This topic was modified 1 year, 7 months ago by den1sa.
    • This topic was modified 1 year, 7 months ago by den1sa.
Viewing 2 replies - 1 through 2 (of 2 total)
  • @den1sa

    I can do this in an Ultimate Member form, but I cannot seem to achieve the same result in a standard webpage that I wish to use for registration.

    This code snippet is copied from another membership plugin which is not supported in this Forum.

    Thread Starter den1sa

    (@den1sa)

    Apologies, thanks for pointing this out. I have now copied it to the Paid Membership Pro forum.

    • This reply was modified 1 year, 7 months ago by den1sa.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Populate field 2 based on field 1 selection’ is closed to new replies.