Hidden Form & _POST

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
better.in.design
Forum Newbie
Posts: 1
Joined: Fri Nov 12, 2010 12:52 pm

Hidden Form & _POST

Post by better.in.design »

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>';
?>
This is just a snippet of my code. The php script itself is called test.php and so it calls itself once the form is submitted. I keep having problems retrieving the data back correctly; I am testing in retrieving the data on the same script from the same page before retrieving the POST data from another webpage.

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?
Post Reply