Last active
October 18, 2018 00:23
-
-
Save spivurno/8481177 to your computer and use it in GitHub Desktop.
Gravity Forms: Example of conditionally requiring a field based on the value of another field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gravity Forms: Example of conditionally requiring a field based on the value of another field. | |
*/ | |
add_filter( 'gform_pre_render', 'gw_conditional_requirement' ); | |
add_filter( 'gform_pre_validation', 'gw_conditional_requirement' ); | |
function gw_conditional_requirement( $form ) { | |
$value = rgpost( 'input_2' ); | |
if( $value == 'no' ) | |
return $form; | |
foreach( $form['fields'] as &$field ) { | |
if( $field['id'] == 1 ) { | |
$field['isRequired'] = true; | |
} | |
} | |
return $form; | |
} |
Awesome. Thanks!
Hi, thanks for the advice, but I have one question, is that possible to get checkbox status, if is checked or not ? I have a big problem with that
In case anyone's wondering about this, this snippet is at https://docs.gravityforms.com/gform_pre_validation/ so you could ask Gravity Forms' support about "their own" snippet if you have follow-up questions.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can anyone comment on the above point? Need to know the JS solutions as well.