Validating drop down field
-
// this validation if the selected value in the drop down is among the array add_filter( 'gform_field_validation_19_2', 'custom_validationusd101', 10, 4 ); function custom_validationusd101( $result, $value, $form, $field ) { $choices = array( array( 'value' => 'MALAYSIA', 'text' => 'NIGERIA'), array( 'value' => 'CHINA', 'text' => 'CHINA'), array( 'value' => 'UNITED', 'text' => 'UNITED STATES'), array( 'value' => 'LONDON', 'text' => 'LONDON'), array( 'value' => 'SPAIN', 'text' => 'SPAIN'), array( 'value' => 'ITALY', 'text' => 'ITALY'), array( 'value' => 'TURKEY', 'text' => 'TURKEY'), array( 'value' => 'ROMANIA', 'text' => 'ROMANIA'), ); $mango = $choices; $mango = array( 'value' => 'CHINA' ); if (!in_array($value, $mango)) { $result['is_valid'] = false; $result['message'] = 'Sorry, your selection was not part of the options in the array!.'; } return $result; }
i have updated the code, this seems to work if only china is selected from the drop down option, but my concept is that if any of the values in the array is selected, not just china, and i don’t want to be repeating all the values again one by one in the validation code, i want it to be as a single variable that i can use to show values of choices as listed in the array.
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Validating drop down field’ is closed to new replies.