Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Garconis/36889d2fdd6ede09e6d15a9b82174cbf to your computer and use it in GitHub Desktop.
Save Garconis/36889d2fdd6ede09e6d15a9b82174cbf to your computer and use it in GitHub Desktop.
Gravity Forms | Conditionally require certain form fields based on the page its on
<?php
// Conditionally requiring (or un-requiring) certain Contact Form fields based on the page its on
// https://gist.github.com/spivurno/8481177
function fs_conditional_requirement( $form ) {
// homepage
if ( is_page(15) ) {
foreach( $form['fields'] as &$field ) {
// Company field
if( $field['id'] == 22 ) {
$field['isRequired'] = false;
}
// Project Type dropdown
if( $field['id'] == 23 ) {
$field['isRequired'] = false;
}
}
return $form;
}
return $form;
}
add_filter( 'gform_pre_render_6', 'fs_conditional_requirement' );
add_filter( 'gform_pre_validation_6', 'fs_conditional_requirement' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment