Skip to content

Instantly share code, notes, and snippets.

@spivurno
Last active October 18, 2018 00:23
Show Gist options
  • Save spivurno/8481177 to your computer and use it in GitHub Desktop.
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.
<?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;
}
@prionkor
Copy link

prionkor commented Nov 1, 2016

Can anyone comment on the above point? Need to know the JS solutions as well.

Copy link

ghost commented May 3, 2018

Awesome. Thanks!

@MatusVrsansky
Copy link

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

@cliffordp
Copy link

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