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
How to Send Notification to Android from PHP
Adding Multiple Items to Woocommerce Cart at Once
How to Wrap Long Lines Without Spaces in HTML
How to Replace Multiple Items from a Text String in PHP
Php's File_Exists() Will Not Work for Me
Yii2:Activequery Example and What Is the Reason to Generate Activequery Class Separately in Gii
How to Access Discriminator Field from PHP in Doctrine2
How to Install the Intl Extension for Twig
Redirecting Wordpress's Login/Register Page to a Custom Login/Registration Page
Highlight Multiple Keywords in Search
Php: How to Generate a Hmacsha256 Signature of a String
Is There an Equivalent in C++ of PHP's Explode() Function
Require_Once :Failed to Open Stream: No Such File or Directory
Windows Cmd.Exe "The System Cannot Find the Path Specified."