Last active
April 26, 2020 04:45
-
-
Save kjohnson/9eca4cf57052787ced517e0ff2e81b7e to your computer and use it in GitHub Desktop.
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 | |
add_filter( 'ninja_forms_submit_data', function( $form_data ){ | |
if( ! my_nf_validation( $form_data ) ) { // Add check here. | |
$errors = [ | |
'fields' => [ | |
'12' => __( 'An unexpected error occurred.', 'my-plugin' ) | |
], | |
]; | |
$response = [ | |
'errors' => $errors, | |
]; | |
echo wp_json_encode( $response ); | |
wp_die(); // this is required to terminate immediately and return a proper response | |
} | |
// If no errors, be sure to return the $form_data. | |
return $form_data; | |
}); |
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 | |
add_filter( 'ninja_forms_submit_data', function( $form_data ){ | |
if( ! my_nf_validation( $form_data ) ) { // Add check here. | |
$errors = [ | |
'form' => [ | |
'my-error' => __( 'An unexpected error occurred.', 'my-plugin' ), | |
] | |
]; | |
$response = [ | |
'errors' => $errors, | |
]; | |
echo wp_json_encode( $response ); | |
wp_die(); // this is required to terminate immediately and return a proper response | |
} | |
// If no errors, be sure to return the $form_data. | |
return $form_data; | |
}); |
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 | |
add_filter( 'ninja_forms_submit_data', function( $form_data ){ | |
if( ! my_nf_validation( $form_data ) ) { // Add check here. | |
$errors = [ | |
__( 'An unexpected error occurred.', 'my-plugin' ) | |
]; | |
$response = [ | |
'errors' => $errors, | |
]; | |
echo wp_json_encode( $response ); | |
wp_die(); // this is required to terminate immediately and return a proper response | |
} | |
// If no errors, be sure to return the $form_data. | |
return $form_data; | |
}); |
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 | |
// Form Error | |
$errors[ 'form' ][ $error_id ] = 'Form Error'; | |
// Field Error | |
$errors[ 'fields' ][ $field_id ] = 'Field Error'; |
The same for me.
Same for me :(
Same for me...
The same was for me.
I found out, that you should return the response and without JSON encoding.
Also I was unable to display "form error", just "field error":
add_filter( 'ninja_forms_submit_data', 'my_ninja_forms_submit_data' );
function my_ninja_forms_submit_data( $form_data ) {
$errors = [
'fields' => [
'5' => __( 'An unexpected error occurred.', 'my-plugin' ),
]
]; // '5' is field's id.
$response = [
'errors' => $errors,
];
return $response;
}
Does anyone else get "Call to undefined function my_nf_validation()" error message?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Am I missing something, the "Submit" button continues to show "Processing" after the JSON returns. (NF 3.3.7)