Forums

[resolved] How to process data acquired by POST method? (8 posts)

  1. SAnton
    Member
    Posted 3 years ago #

    Hello.

    I have installed EXEC-PHP plugin which allows me to put PHP scripts into my pages. I created a simple page with the following content:

    <?php
    echo '<pre>';
    print_r($_POST);
    echo '</pre>';
    ?>
    <form method="post">
    <input type="text" name="name"/>
    <input type="submit"/>
    </form>

    When I open this page, it's works as intended, showing me the following text:

    Array
    (
    )

    and the input form.

    When I press the "Submit" button with empty text input field, I get the following:

    Array
    (
        [name] =>
    )

    Everything is still excellent. But when I enter some text to the input field and press "Submit", I'm getting "Sorry, but you are looking for something that isn't here."

    How to fix this? Where in the WordPress's code the checking of POST data presence is performed??

  2. SAnton
    Member
    Posted 3 years ago #

    I have solved it. The problem is that "name" is a reserved name for WP internal usage. I just changed the name to ABCDEF, and everything is fine:

    <?php
    echo '<pre>';
    print_r($_POST);
    echo '</pre>';
    ?>
    <form method="post">
    <input type="text" name="ABCDEF"/>
    <input type="submit" />
    </form>
  3. wc.smith
    Member
    Posted 3 years ago #

    SAnton:

    Man! I don't know how you figured this out, but I am eternally greatful. I have been fiddling with this for the past week trying to figure out what wordpress was doing with a post vice a get and could not figure it out.

    I was experimenting with a simple form to see how it works with a page template and it just so happens that I too had a name="name" on an input tag. Changed it to name="fullname" and it works like a charm.

    Thanks for your insight...

    Warren

  4. paul3eb
    Member
    Posted 3 years ago #

    it'd be great if there were a list of reserved variable names to avoid. does one already exist?

  5. timjamz
    Member
    Posted 3 years ago #

    SAnton: Rock on, dude! I've also been wrastlin' with this - good catch!

  6. Otto
    Tech Ninja
    Posted 3 years ago #

    Hah. Yes.

    It's always a good programming practice to pick unique names for variables. This is not specific to WordPress, but I tend to name things that are submitted something like pluginname_variablename. This ensures that they'll be there, ignoring wild coincidence. :)

  7. idcoder
    Member
    Posted 3 years ago #

    hey santon..awesome dude..thanks a lot for helping us out here..awesome awesome yoyoyoyoyo..thanks

  8. goodpasture
    Member
    Posted 3 years ago #

    You should also take the 'action=...' part out of the form tag if you have one in your form. Your post helped be on this but only wish I found it a few hours earlier.

    thanks,
    Jonathan

Topic Closed

This topic has been closed to new replies.

About this Topic