• I have a plugin that creates forms with nonces using wp_nonce_field. I have a simple form function that works fine, but the problem is that it causes a redirect error when updating a page with that shortcode on it. I am working in Classic mode under the Text view.

    Here is the function:

    function yyz_home_form_2nd_top () {
    	return '
    		<form action="/contact/thank-you" method="post">
    			<input type="email" id="email" name="email" required class="demo-email" placeholder="Email address"><input type="submit" value="See a Demo" class="demo-submit">
    			<input type="hidden" id="form_name" name="form_name" value="See a Demo (Email only)">' . 
    			wp_nonce_field('my_nonce', 'yyz_simple_form') .  
    		'</form>';
    }
    
    add_shortcode('see_demo_form', 'yyz_home_form_2nd_top');

    Here is the error I get when I save the page:

    Warning: Cannot modify header information - headers already sent by (output started at /home/(my_domain_folder
    )/public_html/wp-includes/functions.php:1831) in /home/(my_domain_folder)/public_html/wp-admin/post.php on line 231

    Here is what I see in developer tools of the page:

    <body><input type="hidden" id="_wpnonce" name="_wpnonce" value="6bee3d0ad8"><input type="hidden" name="_wp_http_referer" value="/wp-admin/post.php"><br>
    <b>Warning</b>:  Cannot modify header information - headers already sent by (output started at /home/primaryi/public_html/wp-includes/functions.php:1831) in <b>/home/primaryi/public_html/wp-admin/post.php</b> on line <b>231</b><br>
    </body>

    So, for some reason, it’s printing out the nonce fields while still on the edit page.

    I have used wp_nonce_field in a different function without it doing this and I cannot for the life of me figure out why I’m getting this with this simple function

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_nonce_field in shortcode function causes redirect error’ is closed to new replies.