• Resolved albtrentadue

    (@albtrentadue)


    Hello
    I created this code snippet, according to forum help, and activated it:

    
    add_action( 'template_redirect', function () { 
    
    	if ( ! is_page( 82154 ) || ! isset( $_POST['name'] ) ) {
    		return;
    	}
    
    	$name = $_POST['name'];
    	// process submitted data here
    	echo $name;
    
    } );
    

    Then a page with ID 82154 with a form:

    
     
    <form action="" method="POST">
    <label>Nome</label>
    <input name="name" required="" type="text" />
    
    <label>Cognome</label>
    <input name="surname" required="" type="text" />
    
    <label>A quale evento vuoi iscriverti?</label>
    
    <select name="event" required="">
    <option hidden="" selected="selected" value="">-</option>
    <option value="uno">Lorem</option>
    <option value="due">Ipsum</option>
    <option value="tre">Dolor</option>
    <option value="quattro">Sit</option>
    <option value="cinque">Amen</option>
    <option value="sei">Latinum</option>
    </select>
    
    <label>eMail</label>
    <input name="email" required="" type="text" />
    
    <input type="submit" value="Submit" />
    
    </form>&nbsp;
    

    When I test the page, I get a “Oops! Something went wrong…”
    I think I followed the indication, but I cannot understand what is wrong.

    Thanks for help!
    Alberto

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hey Alberto,

    It looks like you can’t really submit posted data to a WordPress page in that way.

    Instead, consider removing the is_page() check from your saving function, and only check based on submitted form data.

    Thread Starter albtrentadue

    (@albtrentadue)

    Hi Shea,
    Thank you for your answer.
    After investigation, I have found out that the problem was not about the Code Snippets plugin.
    Problem was that you cannot define an HTML form in WP with an input field named “name”: it seems that this messes up WP and redirects to 404 page.

    So problem is solved and Code Snippets works very well.

    Kind regards!

    Plugin Author Shea Bunge

    (@bungeshea)

    Ah right, it makes a lot of sense that ‘name’ world be a reserved keyword.

    I’m glad that you managed to sort this out!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Form submit fails’ is closed to new replies.