Last active
February 22, 2023 23:59
-
-
Save rafaehlers/8b6b31d84c18e21f77229ef62f173198 to your computer and use it in GitHub Desktop.
GravityView - Prevent a required field from being required on Edit Entry page
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 // DO NOT COPY THIS LINE | |
add_filter( 'gform_pre_render', 'gravityview_edit_entry_dont_require_fields' ); | |
add_filter( 'gform_pre_validation', 'gravityview_edit_entry_dont_require_fields' ); | |
function gravityview_edit_entry_dont_require_fields( $form ) { | |
if ( ! class_exists( '\GravityView_View' ) ) { | |
return $form; | |
} | |
$view_id = GravityView_View::getInstance()->getViewId(); | |
if($view_id !== 44873){ // Replace 44873 with your View ID | |
return $form; | |
} | |
foreach ( $form['fields'] as &$field ) { | |
if ( $field->id == 6) { // This is the ID of the Email field on form 37 | |
$field->isRequired = false; | |
//$field->validation_message = "Not Required"; | |
} | |
} | |
return $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment