Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

rcorr on "Displaying a custom error message"

$
0
0

Hello,

I am following along a tutorial in Yannick Lefebvre Plugin Cookbook on saving user-submitted content. The form saves the data in the database correctly, however if a required field is missing, I received the following instead of the abort message I provided (see below):

Comment Error
Please enter all fields correctly to post a comment.

I believe this is the default message for the comment form. The code I have is

if ( wp_verify_nonce( $_POST['br_user_form'],'add_review_form' ) &&
!empty( $_POST['book_title'] ) &&
!empty( $_POST['book_author'] ) &&
!empty( $_POST['book_review_text'] ) &&
!empty( $_POST['book_review_book_type'] ) &&
!empty( $_POST['book_review_rating'] ) ) {
   // Insert data in database and other stuff
   exit;
} else {
  // Display message if any required fields are missing
  $abortmessage = 'Some fields were left empty. Please ';
  $abortmessage .= 'go back and complete the form.';
  wp_die($abortmessage);
  exit;
}

To confirm that the program reaches the error block, I placed a JavaScript alert just before the $abortmessage variable and it shows up. Therefore, I am reaching that block of code if a field is empty.

If anyone can shed some light why the custom error message does not show, I will be much appreciated.

Thanks in advance.


Viewing all articles
Browse latest Browse all 8245

Trending Articles