The nonce field is not added to the form, and is therefore not passed in the POST request when submitting the form. Thus, isset( $_POST['post_nonce_field'] )
returns false
and the conditional is never true. Try moving the nonce field to someplace between the opening form tag ( <form>
) and closing form tag (</form>
).
EDIT: The problem is actually in your JavaScript. The “submit” link you currently have submits the form, but doesn’t stop propagation of the normal on click event for a link, which is actually following the link. Thus, as the href
attribute is empty, it will actually point you to the current page via a normal GET request.
To fix this, you could add return false;
right behind the submit()
JavaScript method call for the form. However, a better way to achieve this would be to use a button
or submit
element, or at least call the form submission function through JavaScript so you can use preventDefault
instead of returning false.
TL;DR Use a button or input submit element (best choice), call the submit through jQuery and add e.preventDefault()
(second best) or add return false;
after the JavaScript submit()
call (worst — but easiest — solution).