WordPress.org

Support

Support » How-To and Troubleshooting » Submitting form to WordPress page

Submitting form to WordPress page

  • I’ve made a page template which has a form. I’ve left the ‘action’ part of the form blank so the form submits to itself (action=””), and am using POST data (method=”post”). However when I submit the form, the URL doesn’t change (correct) but I get a 404 error – why is this?

    I’m using ‘pretty’ permalinks if that helps.

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’ve just tried that and can’t reproduce the problem. Here’s the code I used:

    <?php
    /*
    Template Name: Form
    */
    ?>

    <?php get_header(); ?>

    <?php echo ‘We have got: ‘ . $_POST[‘f1’] . ”; ?>
    <form action=”” method=”POST”>
    <input type=”text” name=”f1″ value=”test”/>
    <input type=”submit” name=”submit” value=”Submit”/>
    </form>

    <?php get_footer(); ?>

    Submitting the form shows the value of the input field as expected; no 404.
    Maybe a plugin that’s interfering here. Have you tried this on a fresh installation?

    Hi chschenk, and thanks for looking into the problem for me. Your form worked for me so I started looking at my own form. Turns out the problem was caused by one of my input’s being called ‘name’. Try this:

    <?php
    /*
    Template Name: Form
    */
    ?>
    
    <?php get_header(); ?>
    
    <?php echo 'We have got: ' . $_POST['name'] . ''; ?>
    
    <form action="" method="POST">
        <input type="text" name="name" value="test"/>
        <input type="submit" name="submit" value="Submit"/>
    </form>
    
    <?php get_footer(); ?>

    On my WordPress install this produces a 404 error page.

    I get a 404 here too but can’t tell whether that happens; excuse: haven’t had a detailed look at it.

    I’d say, just avoid naming your input fields “name” 😉

    Thanks – I was using the post names of “author”, “title” and “description” and was getting this error. I modified them to “ad_author”, “ad_title”, (I’m making a simple classifieds board for our intranet) and that took care of it.

    Thanks for the tip! – I would call this resolved.

    iglauser

    @iglauser

    Thanks! Searched a long time for a solution to this problem, and now I found it on this page… name=”name” 🙂

    Thanks guys. Weird, but thanks for the answer.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Submitting form to WordPress page’ is closed to new replies.
Skip to toolbar