Radio Button Validation

Hi,

I noticed that another site had validation added onto Radio Buttons, and was just wondering how to add that myself?

Example: If the user selects Yes then the Validation should display. But if the user selects No then the user should be able to go the next step of the form.

This is the link I found the working example, under the Health step just select Yes: https://wmda.info/donor/become-a-donor/#gf_22

This is what I have tried so far but I am now receiving a validation for both Yes and No, which is incorrect:

add_filter( 'gform_field_validation_4_5', 'custom_validation');
     function custom_validation($value){
        if($result['$value'] = No){
	    $result['$value'] = Yes;
	    $result['message'] = 'Unfortunately you cannot become a blood stem cell donor.';
      }
      return $result;
  }

Kind regards,
Dale

Please refer back to this example:

You need to check if the result is valid (meaning nothing else already failed validation) and if they submitted yes ( "$value == 'Yes' ) THEN, set the validation message to “Unfortunately, you cannot…” AND also set the is_valid to FALSE (saying the submission is invalid).

Take a look at the differences between the code in the example, and your code and update to compare the correct items, and post your results here. Thank you.

Hi,

I still get the same error message on both options.

add_filter( 'gform_field_validation_4_5', 'custom_validation');
  function custom_validation($value){
     if ( ["$value == 'Yes'"]) {
    $result['is_valid'] = false;
    $result['message'] = 'Unfortunately you cannot become a blood stem cell donor.';
   }
   return $result;
 }