How to Post Button Value to PHP

How do I post button value to PHP?

Change the type to submit and give it a name (and remove the useless onclick and flat out the 90's style uppercased tags/attributes).

<input type="submit" name="foo" value="A" />
<input type="submit" name="foo" value="B" />
...

The value will be available by $_POST['foo'] (if the parent <form> has a method="post").

Send value of submit button when form gets posted

The button names are not submit, so the php $_POST['submit'] value is not set. As in isset($_POST['submit']) evaluates to false.

<html>
<form action="" method="post">
<input type="hidden" name="action" value="submit" />
<select name="name">
<option>John</option>
<option>Henry</option>
<select>
<!--
make sure all html elements that have an ID are unique and name the buttons submit
-->
<input id="tea-submit" type="submit" name="submit" value="Tea">
<input id="coffee-submit" type="submit" name="submit" value="Coffee">
</form>
</html>

<?php
if (isset($_POST['action'])) {
echo '<br />The ' . $_POST['submit'] . ' submit button was pressed<br />';
}
?>

PHP, html: How to pass the button value to post

If you want it to have a value, give it one using the value attribute:

<button type="text" name="class_id" value="some_value">

See <button> on MDN

PHP Get name value from submit button

Try this:
Separate the name with asymbol and then split.

<input type="submit" name="<?php echo $tournament.'_'.$weekNumber ?>"  />

foreach($_POST as $name => $content) {
//echo "The TOURNAMENT NAME IS: $name <br>";
list($tournament, $round) = explode('_', $name);
}


Related Topics



Leave a reply



Submit