Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm writing code from within a plugin and I'm attempting to create a two-part registration form. I'm using POST to determine if the first part of the form was submitted or not. Unfortunately, though, the POST data is not coming through. Here is what my form looks like:

<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
<input type="submit" name="user_info_form" id="user_info_form" />
</form>

This should POST back to the same page, in theory. I then use the below code to read the POST data.

if(isset($_POST['user_info_form']))
{
echo "found data";
}
else
{
echo "nothing found";
}

Unfortunately, "nothing found" is being outputted following a form submission.

Is there any reason for this that has to do with WordPress? I've been at this for hours now so any help is very much appreciated!

share|improve this question
    
what do you get when you print_r( $_POST )? –  m0r7if3r Feb 2 '12 at 11:20
    
I'm getting all of the other POST data, so that seems to be working okay. However, I'm not getting the submit button's post data which means it's not being sent to the right place maybe? What should the action of the form be? –  Evan Feb 2 '12 at 15:48
    
try just action='', see if that gets the post data in there –  m0r7if3r Feb 2 '12 at 23:13
    
That was the first thing I tried :) –  Evan Feb 4 '12 at 2:01
    
If you use Chrome's 'Inspect Element' tool (or equivalent in your browser of choice), what do you see for the action of the form? –  m0r7if3r Feb 4 '12 at 3:39

4 Answers 4

<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
<input type="submit" name="user_info_form" id="user_info_form" />
</form>

I think there is a syntax error in the PHP. It should end with a semicolon, like this:

<form action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="post">
<input type="submit" name="user_info_form" id="user_info_form" />
</form>
share|improve this answer
1  
not a syntax error. –  Milo Jul 8 at 2:32
up vote 0 down vote accepted

I found my own answer on this one (just now). The stupid plugin had javascript at the bottom of the page disabling all submit buttons from working - what a joke, sorry everyone.

share|improve this answer

What about adding a hidden input field to the code?

<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
    <input type="hidden" value="1" name="form_submitted" />
    <input type="submit" name="user_info_form" id="user_info_form" />
</form>

Then compare to the hidden field's value. Does that make any difference?

share|improve this answer

Did you try adding a value to the input field? It looks like you are using a submit input field, not a text input field. <- Never mind, it still isn't null after submitting.

In order to troubleshoot, try adding the following to the top of your code:

<?php
echo 'Post variables:<br />';
print_r($_POST);
?>

Also, where are you placing this code? I dropped your code straight in to the header.php file of a custom theme and it worked as expected.

share|improve this answer
    
Yes, I'm checking to see if the submit button was clicked. I do not care about the text field. Did I misunderstand you? –  Evan Feb 2 '12 at 4:21
    
Actually, I just checked, even with no specified value in the submit input field, I'm still seeing 'Submit' come through. I've edited above, have a look. –  Exit Feb 2 '12 at 4:32
    
Sorry, but what did you edit? I don't see any changes :) –  Evan Feb 2 '12 at 4:35
    
Check again, was sidetracked... –  Exit Feb 2 '12 at 4:45
    
All of the code you see there is inside of a plugin file which I believe becomes part of a page (I'm 99.99% positive about that). So, to answer your question, I'm posting and retrieving the post from inside of a wordpress page. What should I be putting in the header?? –  Evan Feb 2 '12 at 5:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.