Jump to content

Hidden Form & _POST


better.in.design

Recommended Posts

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?

 

 

<!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>';
?>

Link to comment
Share on other sites

I've tried that and I see the value for $decimalSum is 0 after submitting the form with the first name field filled with a name.  It seems to imply that there is something wrong on the line where $decimalSum is computed.  This doesn't make sense to me since the echo statement right after it's computation shows its value.  For some reason, this value is not sent to POST.  If I resend the same checked field again, the value goes through.  Do you know something I don't?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.