Jump to content

$_POST is empty and refuses to be anything else


Dingbats

Recommended Posts

I have this form:

 

<form action="index.php?loc=buy" method="POST">
  <p><input type="text" id="email" value="Your e-mail address" />
  <textarea id="message">What do you want?</textarea>
  <input type="hidden" id="submitcheck" value="1" />
  <input type="submit" id="submit" value="Send" /></p>
</form>

 

At the top of the file, I'm checking to see if anything's been posted, I've tried both if (isset($_POST["submitcheck"])) and if (array_key_exists("submitcheck", $_POST)).  Both always return false.  var_dump($_POST) returns "array(0) { }".

 

From a quick Google search I get the impression that this is probably some kind of problem with the configuration, and not the code.  However, I'm completely lost when it comes to fixing it.  I should mention that GET works fine.

 

Any ideas?

Link to comment
Share on other sites

you need to add a name="" to your input fields, as that's what the $_POST superglobal checks for:

 

<form action="index.php?loc=buy" method="POST">
  <p><input type="text" name="email" id="email" value="Your e-mail address" />
  <textarea name="message" id="message">What do you want?</textarea>
  <input type="hidden" name="submitcheck" id="submitcheck" value="1" />
  <input type="submit" name="submit" id="submit" value="Send" /></p>
</form>

 

EDIT:  you can lose the id="" from each input, unless you are using them for another reason.  they will not work for what you are trying to do though.

Link to comment
Share on other sites

Thanks for your quick replies.

 

I had tried (I just didn't mention it for brevity) checking for $_POST["submit"] and using name instead of id, but it never worked.

 

Now, for some totally inexplicable reason, when I tried exactly the same thing again, it works.  I'm amazed and confused.

 

Thanks again, consider this solved.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.