WordPress.org

Ready to get started?Download WordPress

Forums

posting form to custom template results in 404 (8 posts)

  1. analogue40
    Member
    Posted 5 years ago #

    Hi all,

    I have a very strange problem, and I hope someone can help me out.

    I have created a very basic custom template, that contains a form, that is submtted back to the template.

    If I enter any data into the form fields then I get a 404 error back from wordpress.

    If I leave the form fields empty wordpress acepts the form (even if their are hidden fields).

    You can see for yourself here:

    http://blossombeinspired.com/test/

    submit the form without data and you'll get a 'form submitted okay message', add anything to in the form field and it returns a 404.

    ANY help whatsoever appreciated, I have been trying to sort this for hours.

    PS form works fine when not part of wordpress, I have also tried other versions of wordpress (2.0), and also tried 2 different servers and the same thing happens.

    This is the code:

    if ($_SERVER['REQUEST_METHOD'] == GET){
    ?>
    <form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">

    Name: <input type="text" name="name" value="">
    <input type="hidden" name="foo" value="bar">

    <input type="submit" value="Submit">
    </form>
    <?php
    }
    else if ($_SERVER['REQUEST_METHOD'] == POST){
    echo "form submitted okay";
    }

  2. analogue40
    Member
    Posted 5 years ago #

    I haven't solved this problem, but rather made a workaround based on another reply I found on these forums.

    Instead of creating a template and the creating a page in wordpress based on this template, I just added the following to the top of my file:

    <?php
    /* Don't remove this line. */
    require($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php');
    ?>

    and then just following this just create the page like it was a wordpress template.

    Then, to get pretty URLS I manually added the .htaccess entries to point to the file in my theme folder, for instance:

    RewriteRule admin$ /wp-content/themes/mytheme/my_custom_template.php [L]

    this sends anyone who goes to mysite.com/admin to mysite.com/wp-content/themes/mytheme/my_custom_template.php

    and it finally works.

    If anyone needs any help let me know.

  3. mrpunkin
    Member
    Posted 5 years ago #

    Me too... has anyone found a solution to this? I can't see why it wouldn't work.

  4. ianstapleton
    Member
    Posted 5 years ago #

    I had this exact same problem, and the solution I came across was annoyingly simple - don't submit a form field called "name": change

    <input type="text" name="name" value="">
    to
    <input type="text" name="myName" value="">

    as soon as I did this, everything started working.

    iAn

  5. gus.marcos
    Member
    Posted 5 years ago #

    wow!! you're great, man!

  6. analogue40
    Member
    Posted 5 years ago #

    ianstapleton,
    Cheers for posting the solution to this, just came across this problem again and came back on the off chance someone had replied to this post.

    I can't beleive how much time I wasted last time looking for a solution to this, installed multiple version of wordpress and all sorts.

    a40

  7. spiff06
    Member
    Posted 5 years ago #

    Lots of wasted time here too, glad I found this post though. Thanks loads.

    Odd though, that a form with a name set to "name" would fail to parse. This has to be a WordPress cleanup issue, or a security "feature" perhaps? Did anyone investigate this?

  8. aflusche
    Member
    Posted 5 years ago #

    Awesome!! I was wrangling with this exact same issue. Changing the "name" field to something else fixed it.

Topic Closed

This topic has been closed to new replies.

About this Topic