Could you please tell me the difference between submitting a submit button value and submitting a hidden input value?
I ask the question especially in regard of the browser compatibility (IE 9+).
So, my problem is actually the following: I know that a posted hidden input value is always correctly read by the server. But I'm not sure if this is the case too, if the value (which I want to post) is part of the "value" attribute of a <button> tag.
Thank you very much for your time!
P.S: I prepared an example for clarity. It contains a form for each option in my question. When one of the forms is submitted, the corresponding values are read in PHP. Relevant is the user id value.
<?php
if (isset($_POST['submitUserId']) && !empty($_POST['submitUserId'])) { // Submitted values.
$userId = $_POST['submitUserId'];
$userName = $_POST['userName'];
echo 'Posted user id: ' . $userId;
echo '<br/>';
echo 'Posted user name: ' . $userName;
// Save the new values in db...
} else { // Initial values fetched from db.
$userId = 123;
$userName = 'Valentine';
echo 'Initial user id: ' . $userId;
echo '<br/>';
echo 'Initial user name: ' . $userName;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test - Submit button value vs. hidden input value</title>
</head>
<body>
<h4>Option 1: Submit <i>user id</i> as submit button value</h4>
<form action="" method="post" id="formButtonValue" name="formButtonValue">
<input type="text" id="userName" name="userName" value="<?php echo $userName; ?>" />
<button type="submit" id="submitUserId" name="submitUserId" value="<?php echo $userId; ?>">
Submit user details
</button>
</form>
<h4>VS.</h4>
<h4>Option 2: Submit <i>user id</i> as hidden input value</h4>
<form action="" method="post" id="formHiddenInputValue" name="formHiddenInputValue">
<input type="text" id="userName" name="userName" value="<?php echo $userName; ?>" />
<input type="hidden" id="submitUserId" name="submitUserId" value="<?php echo $userId; ?>" />
<button type="submit" id="submitButton" name="submitButton">
Submit user details
</button>
</form>
</body>
</html>