I am trying to check that the user has made a selection from the dropdowns. They are required to make a selection from 3 of the 5 dropdowns (counting dropdowns successfully.) The function below does what I need EXCEPT being able to check the text/value of the dropdown to be certain 3 out of the 5 DO NOT have the default value selected (“Select One”). If the user does not select 3 of the 5, then the form may not continue to the next page.
add_filter( 'gform_validation_11', 'validate_selection_count' );
function validate_selection_count( $validation_result ) {
// initialize counter
global $counter;
$counter = 0;
// Get the form object from the validation result
$form = $validation_result["form"];
// Get the current page being validated
$current_page = rgpost('gform_source_page_number_' . $form['id']) ? rgpost('gform_source_page_number_' . $form['id']) : 1;
if ($current_page == 4){
foreach ($form['fields'] as &$fields) {
$is_hidden = RGFormsModel::is_field_hidden( $form, $fields, array() );
if($is_hidden){
continue;
}
if($fields['type'] == 'select' && **<compare value or text here>**){
$counter++;
}
}
if ( $counter != 3){
$validation_result['is_valid'] = false;
}
}
return $validation_result;
}
I found this page (Getting Selected Dropdown Text/Value - #4 by chrishajer) that I think should give me what is needed, but can’t get it to work .
How can I get either the text or the value of the dropdown to see which dropdowns the user has made a selection from?