Support

Account

Home Forums Front-end Issues Select field based on other fields value

Solving

Select field based on other fields value

  • I have created two text fields that will display on a registration form.

    After the registration based on these two text fields I want to display their values as a select field.

    Is this possible? Is there a way to create a select field which will take choices based on another fields values?

    I can display these fields on a select field with the following code but the problem here is that I cannot save the choise value.

    
    <select name="cars" id="cars">
    	<option value=" <?php the_field('car_type_1'); ?> " > <?php the_field('car_type_1'); ?> </option>
    	<option value=" <?php the_field('car_type_2'); ?> " > <?php the_field('car_type_2'); ?> </option>
    </select>
    
  • After doing some research I think that the best way to achieve this is by creating a repeater field with a text subfield.

    The question now is how can I display this repeater field as a select field with the values of the text subfields and how can I save the value from the select field choise (the repeater field will display in a registration form).

  • UPDATE
    So I’ve managed to display the repeater field as a select box with the following code

    <select name="cars" id="cars">
    <?php
    // Check rows existexists.
    
        // Loop through rows.
        while( have_rows('yacht_type1') ) : the_row();
    
            // Load sub field value.
            $sub_value = get_sub_field('name');
            // Do something...
    	
    		echo '<option value="'.$sub_value.'">'.$sub_value.'</option>';
    	endwhile;
    ?>
    </select>

    Now what I’m actually searching for is how to get and store the value from the select box.

  • I’m not sure I understand completely what you are trying to do, so this may or may not be helpful.

    Created an options page. On the options page you have a repeater with a text sub field. You enter all of the possible values that you want in the select field. Then you create a select field where you want to use these values and you dynamically populate the choices.

  • Actually you helped a lot.
    I was trying to populate the choises from a field group that was showing on users.

    Is it possible to do this on a field group that is showing somewhere else besides options page?
    I’m trying to show this field group on users panel but the populate functions doesn’t work there.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.