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?

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.