Is there a way to send a notification despite the fact that validation fails.
I have written this custom validation which checks if a gform field is less than another one, if it is, it sets $result[‘is_valid’] = false; allowing the send process to stop and the custom validation message to show.
add_filter( 'gform_field_validation_1_5', function ( $result, $value, $form, $field ) {
$min_offer = rgpost( 'input_9' );
if ( $result['is_valid'] && $value <= $min_offer ) {
$result['is_valid'] = false;
$result['message'] = 'Unfortunately your offer is too low. Please feel free to try again.';
}
return $result;
}, 10, 4 );
However the client wants to be notified by email in this case, is there a way I can show my custom validation message but also send all entry fields to an email?
Thanks for this, I hope this doesn’t seem to silly to you but I can’t seem to get it to output the entry details in the email, when I try to add $entry as an argument to the function it just hangs on submission, have I written the syntax wrong?
//$entry added to arguments
add_filter( 'gform_field_validation_1_5', function ($result, $value, $form, $entry, $field) {
$min_offer = rgpost( 'input_9' );
if ( $result['is_valid'] && $value <= $min_offer ) {
//new line added here
GFAPI::send_notifications( $form, $entry );
$result['is_valid'] = false;
$result['message'] = 'Unfortunately your offer is too low. Please feel free to try again.';
}
return $result;
}, 10, 4 );
You went a little crazy with the parameters there. You have five listed in your function call:
add_filter( 'gform_field_validation_1_5', function ($result, $value, $form, $entry, $field) {
but the last line of your code (10, 4) only looks for 4 parameters.
If you check the documentation for gform_field_validation, you can see that only 4 parameters are accepted, and $entry is not one of them. The entry is not created at that point. You will need to use $_POST instead. You don’t need to pass it in, so the first line of your code should look like this:
add_filter( 'gform_field_validation_1_5', function ( $result, $value, $form, $field ) {
Then, you can use rgpost to read the $_POST global:
I’ve had a rethink of this and don’t think I even need to force a send at the validation stage, as I could think of a way to do this with a simple conditional confirmation instead, thanks for your input in any case.