Populate select field after user input
-
Let me first say: “I know this question is not specific related to ACF Extended” still I’m asking it here because this is an very active support forum and my last resort… ACF support, ACF forum, Stackoverflow… Nothing. And I have to believe my question is not that hard to answer.
To share and to let everyone see I’m not ‘just asking without trying’:
How to populate a select field with values of a textarea on an option page:
function acf_load_color_field_choices( $field ) { // reset choices $field['choices'] = array(); // get the textarea value from options page without any formatting $choices = get_field('my_select_values', 'option', false); // explode the value so that each line is a new array piece $choices = explode("\n", $choices); // remove any unwanted white space $choices = array_map('trim', $choices); // loop through array and add to field 'choices' if( is_array($choices) ) { foreach( $choices as $choice ) { $field['choices'][ $choice ] = $choice; } } // return the field return $field; } add_filter('acf/load_field/name=color', 'acf_load_color_field_choices');
How to show/hide a field after user makes a selection in a frontend form:
add_filter('acf/prepare_field/name=booking_time_session_1', 'yl_check_booking_setting_exceptions_session_1'); function yl_check_booking_setting_exceptions_session_1($field){ // Reset conditions // Warning: Conditions set in the UI won't be compatible! $conditions = array(); // Creating Base Condition $conditions[] = array( array( 'field' => 'field_5ed4181bd63dc', 'operator' => '!=', 'value' => '2', ) ); if(have_rows('booking_setting_exceptions', 'booking_settings')): while(have_rows('booking_setting_exceptions', 'booking_settings')): the_row(); $date = date_i18n('Ymd', strtotime(get_sub_field('booking_setting_exceptions_date', 'booking_settings'))); // Check: Booking Settings Exceptions Date if(empty($date)) continue; // Adding a new AND condition inside Base condition, at the index = 0 $conditions[0][] = array( 'field' => 'field_5ed4178dd63d7', 'operator' => '!=', 'value' => $date, ); endwhile; endif; // Setting the full condition $field['conditional_logic'] = $conditions; return $field; }
So what my problem is? Simple.
I have an ACF option page with some fields:
Repeater field:
subfield 1: DATE (datepicker)
subfield 2: SESSION (select field: Lunch / Dinner)Textarea field 1:
With booking times for lunchTextarea field 2:
With booking times for dinnerThese values should blackout date/session combi’s in a frontend booking form.
F.I.: In the option page > repeater field > I have > 30th of July + Lunch
So on the frontend form, when people select booking date 30th of July > The booking TIME field only populates with the DINNER TIMES (because I blackedout Lunch on this date).
I even tried paid services but that really doesn’t help.
I’m willing (and will) to pay drinks ??
- The topic ‘Populate select field after user input’ is closed to new replies.