Hiding the Confirm Email field on the Edit Entry page
If your form is using the Confirmation Email field option on your form to prevent typos, you might want to disable this field on the Edit Entry page of your View.
Below is the code snippet you'll need to hide the Confirm Email from the Edit Entry page of your View:
add_filter( 'gravityview/edit_entry/form_fields', function ( $fields ) {
$view_id = GravityView_View::getInstance()->getViewId();
if ( $view_id !== 321 ) { // CHANGE 321 TO YOUR VIEW ID
return $fields;
}
foreach ( $fields as &$field ) {
if ( 'email' === $field->type && $field->emailConfirmEnabled ) {
$field->emailConfirmEnabled = false;
}
}
return $fields;
} );
add_filter( 'gravityview/edit_entry/field_value', function ( $value, $field ) {
$view_id = GravityView_View::getInstance()->getViewId();
if ( $view_id !== 321 ) { // CHANGE 321 TO YOUR VIEW ID
return $value;
}
if ( 'email' === $field->type && is_array( $value ) ) {
$value = implode( '', $value );
}
return $value;
}, 10, 2 );
Read here how to add these code samples to your website: Where to put code samples.
If you don't want to hide that field, but instead want to automatically prefill it with the same email address from the entry, then that's possible with the code snippet below:
add_filter( 'gravityview/edit_entry/field_value', function ( $field_value, $field ) {
if ( 'email' === $field->type && $field->emailConfirmEnabled && isset( $field_value[ $field->id ] ) ) {
$field_value = [
$field_value[ $field->id ],
$field_value[ $field->id ]
];
}
return $field_value;
}, 10, 2 );
Here's how it will show up on the View: