Home › Forums › Front-end Issues › 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).
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.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.