• Hi –

    This may be the wrong forum to post this, but I’ll give it a shot; hopefully a mod wil move it if its in the wrong place. ??

    I’m in process in working on a custom comment form for my site, and was wondering if there might be a “cleaner” alternative to using wp_die(); when the comment form contains errors (missing name or email, or blank comment).

    I only ask, because it seems odd that WordPress redirects the user to a completely different page, kills everything, and shows them the error with no way back to fix their comment, forcing them to use the back button, and hope their browser saved their progress.

    Any alternatives?

    Thanks!

    – Noel

Viewing 3 replies - 1 through 3 (of 3 total)
  • The usual method is for the form action to reload the page with the comment form. If there’s an error, the user’s data is preserved and some kind of error code in the query string or POST data makes the page display an error message. If all is well, a message thanks the user for commenting.

    By the way, I’ve never understood why comment forms insist on an e-mail address when they accept bogus addresses like [email protected].

    Thread Starter Noel Forte

    (@fortissimo95)

    Hm, that is funny, considering that if I’m running a local version of WordPress I usually just end up putting in a bogus email to create a user account. Email validation can be tricky.

    As far as comment submission goes, is there any way to submit a comment without refreshing the page?

    Just curious.

    Yes, you could use AJAX to submit the comment, and use the response to determine whether to display an error message or an acknowledgement.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Alternative to wp_die() on comment forms?’ is closed to new replies.