Created
April 8, 2024 16:08
-
-
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
This file contains hidden or 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 | |
// 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