1

I have a site with a page where there's one form in the sidebar, and one in the main body of the page. The sidebar comes first in the HTML.

Both forms have their own nonces (generated with wp_nonce_field) with different $action and $name parameters. The $referrer fields are on.

When I submit the second form, I get the usual "Are you sure you want to do this?" message.

If I remove the first form, things work correctly.

I added some debugging to wp_verify_nonce (var_dump statements and an exit;) and it's failing after a NULL $nonce and the $action of the first form (i.e. the one I haven't submitted.)

$_POST contains all of the second form, as you'd expect.

Any ideas?

  • 1
    If you could show your processing logic and the two forms, that would be very helpful in seeing the problem without asking a lot of extra questions. =) – Privateer Jan 31 '15 at 19:43
  • 2
    Try adding a hidden field in both forms, with different values. Check for that Post value before checking the nonce. – shanebp Jan 31 '15 at 20:04
  • 1
    @Privateer as is often the case, about 15 minutes after I'd submitted the question I realised where I'd messed up. Thanks anyway. – William Turrell Feb 1 '15 at 20:42
0

This turned out to be a pretty straightforward bug with my own code.

The problem was my first form was checking for submission with a simple:

if ( 'POST' == $_SERVER['REQUEST_METHOD'] ) {

so it was being triggered even when the other form was submitted, and my wp_verify_nonce() check would fail and then it would call wp_nonce_ays.

To fix, I added this to the conditional:

and isset( $_POST['sidebar_form_wpnonce'] ) 

So yes, you can have more than one form/nonce per page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.