Hidden Form & _POST
Posted: Sat Nov 13, 2010 1:50 pm
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?php
echo '<form enctype="multipart/form-data" method="post" action="test.php">';
echo ' <label for="_firstName">First name : </label>';
echo ' <input type="text" id="_firstName" name ="_firstName">';
echo ' <input type="checkbox" value="1" name="_firstNameChecked"/>';
echo ' <label for="_middleName">Middle name : </label>';
echo ' <input type="text" id="_middleName" name ="_middleName">';
echo ' <input type="checkbox" value="1" name="_middleNameChecked" />';
echo ' <label for="_lastName">Last name : </label>';
echo ' <input type="text" id="_lastName" name ="_lastName">';
echo ' <input type="checkbox" value="1" name="_lastNameChecked" />';
echo '<br />';
echo '<input type="submit" name="Find" value="Find" />';
$firstNameChecked = intval(($_POST['_firstNameChecked']));
$middleNameChecked = intval(($_POST['_middleNameChecked']));
$lastNameChecked = intval(($_POST['_lastNameChecked']));
$decimalSum = (int)((2*2*2)*$firstNameChecked + (2*2)*$middleNameChecked + (2*1)*$lastNameChecked);
$decimalSum = 28;
echo '<br />';
echo '$decimalSum = ' . $decimalSum . '<br />';
echo '<input type="hidden" name="_decimalSum" value = "' . $decimalSum . '" />';
$decimalSum2 = ($_POST['_decimalSum']);
echo '$decimalSum2 = ' . $decimalSum2 . '<br />';
echo '</form>';
echo '</body>';
echo '</html>';
?>
If $decimalSum is a variable that assigns a value that is hard-coded then I would be able to retrieve the same value. However, if the value is computed I can not retrieve it unless I click on the "Find" button twice. This is such a strange behavior and I don't know why.
Does anyone have any suggested solutions to this?