Jump to content

adding key to $_POST when submitting form


niche

Recommended Posts

I need to add a key (with no value) to $_POST when I submit a form. This key is not from the form. I tried $_POST = array("$ankor"=>0);thinking that the submit would just add the form data to the end of $_POST, but no joy as in:

 echo '<form   action="adj_width.php" method="post">';$ankor = "a" . $counter;$counter = $counter + 1;echo '<a name="form_' . $ankor . '"></a>';echo 'Width:<input name="' . $id . '" type="text" />';$_POST = array($ankor=>0);echo '<input type="submit" value="Submit" />';echo '</form>'; 

How do I the key (with no value) from $ankor to $_POST?

Link to comment
Share on other sites

If you're doing it before the form gets submitted, when you output the form, you need to use either a hidden input, or use a Javascript submit handler to add it. If you want to add it after the form gets submitted, in the PHP script that processes the form, you can just set whatever you want, e.g.:$_POST['test'] = '';You can also check if it's set first:if (!isset($_POST['test'])) $_POST['test'] = '';

Link to comment
Share on other sites

I understand. As for the JS apporoach, is "Javascript submit handler" the same thing as "Javascript onsubmit handler"?

Link to comment
Share on other sites

Yes. The event itself is a submit event. When you add an event listener using W3-Compliant addEventListener, you will pass the name of the event as "submit." The "on" prefix should be used when you bind a handler to an element's onsubmit attribute or property.FWIW, everyone knows what you mean when you talk about an onsubmit event. I see more and more people talking about a submit event, and this usage will grow as more time goes by.

Link to comment
Share on other sites

Thanks to justsomeguy & Deirdre's Dad for their help on this topic. I always amazed how so many seemingly different things can be connected.Niche

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...