Get value of dropdown

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?

The approach from the other topic is for use after the form has passed validation and the entry has been saved. For your scenario you’ll need to access the input value from the $_POST which you can do like so:

$value = rgpost( 'input_' . $field->id  );

$value will be empty if the placeholder was selected or will contain the value of the selected choice.

@richardw8k
Maybe I’m not using your code correctly:

$field_value = rgpost(‘input_’.$fields->id );
if($fields[‘type’] == ‘select’ && $field_value = “default” ){
$counter++;
}

but I always get the same result…my counter is 5 when I have made a selection from 2 or 3 dropdowns…or none :frowning: or all.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.