WordPress.org

Ready to get started?Download WordPress

Forums

Submitting form to WordPress page (7 posts)

  1. Nightshade01
    Member
    Posted 5 years ago #

    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.

  2. Christian Schenk
    Member
    Posted 5 years ago #

    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?

  3. Nightshade01
    Member
    Posted 5 years ago #

    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.

  4. Christian Schenk
    Member
    Posted 5 years ago #

    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" ;)

  5. brockangelo
    Member
    Posted 4 years ago #

    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.

  6. iglauser
    Member
    Posted 4 years ago #

    Thanks! Searched a long time for a solution to this problem, and now I found it on this page... name="name" :)

  7. bennthewolfe
    Member
    Posted 4 years ago #

    Thanks guys. Weird, but thanks for the answer.

Topic Closed

This topic has been closed to new replies.

About this Topic