Jump to content

Archived

This topic is now archived and is closed to further replies.

w3sl3y2003

Disappearing values

Recommended Posts

Hi all,

I'm having a problem with self-processing forms (forms that have action=$PHP_SELF) losing their values. What i do is store the values of certain variables in hidden fields. I give the hidden fields the same name as the variables. But as soon as i submit the form, i check the source after the page has been rendered and i see that the values in the hidden fields have disappeared.

Eg.
[b]Before submit[/b]
<form method="POST" action="/app_ed/frmUpdate.php">
<input type="hidden" name="strNewText" value=" This is a test message on the dev webserver ">
<input type="hidden" name="strOldText" value=" This is a test message ">
<input type="submit" name="btnUpdateSubmit" value="Submit" value='Yes/No' onclick='return confirm("Are you satisfied with the new message?");'>
</form>

[b]After submit[/b]
<form method="POST" action="/app_ed/frmUpdate.php">
<input type="hidden" name="strNewText" value="  ">
<input type="hidden" name="strOldText" value="  ">
<input type="submit" name="btnUpdateSubmit" value="Submit" value='Yes/No' onclick='return confirm("Are you satisfied with the new message?");'>
</form>


What could've caused the values to disappear?

Share this post


Link to post
Share on other sites
You haven't posted any of your PHP code here.  Help us to help you  ;)

Regards
Rich

Share this post


Link to post
Share on other sites
okay HuggieBear,

[b]frmSubmit.php[/b]

[code]<html>
<head>
<title>Applet Text Editor</title>
</head>
<body>
<form action="frmUpdate.php" method="POST">
<?php
$preview_file = "scroller/preview_scroller.txt";
$handle = fopen($preview_file, 'r');
$MAX_DATA = 500; //READ IN 500 BYTES OF DATA
$total_data = '';

if(file_exists($preview_file))
{
while($data = fread($handle,$MAX_DATA))
{

$total_data = $total_data. $data; //APPEND INPUT
}

echo "<input type=\"hidden\" name=\"current_scroller_text\" value=\"" .
$total_data .
"\">";

echo "<textarea name=\"txtScrollerText\" rows=8 cols=60>".
    $total_data .
    "</textarea>";

fclose($handle);

}
?>

<br>
<input type="submit" name="btnSubmit" value="submit">
<br>
</form>
</body>
</html>[/code]

[b]frmUpdate.php[/b]

[code]<?php
if(isset($_POST['btnUpdateSubmit']))
{
//header("Location: frmSubmit.php");
//should write "old" text back into preview file
if('return confirm("Are you satisfied with the new message?");')
{
                //        $txtScrollerText = $_POST['txtScrollerText'];
// print("strScrollerText = ".$strScrollerText);
        $production_file = "../scroller/scroller.txt";        
        $prod_handle = fopen($production_file, 'w');
        fwrite($prod_handle,$strScrollerText);
        fclose($prod_handle);

header("Location: frmSubmit.php");
}
else
{
// $current_scroller_text = $_POST['current_scroller_text'];
$preview_file = "scroller/preview_scroller.txt";
$preview_handle = fopen($preview_file, 'w');
fwrite($preview_handle,$strOldPreviewText);
fclose($preview_handle);

header("Location: frmSubmit.php");
}
}
else
{
$strScrollerText = $_POST['txtScrollerText'];
$strOldPreviewText = $_POST['current_scroller_text'];
// print("current_scroller_text : " . $strScrollerText);

$preview_file = "scroller/preview_scroller.txt";
$preview_handle = fopen($preview_file, 'w');
fwrite($preview_handle,$strScrollerText);
fclose($preview_handle);


}

?>
<html>
<body>

<!-- process data stored in variable -->

<form method="POST" action="<? print $_SERVER['PHP_SELF']?>">
<input type="text" name="strScrollerText" value=" <?php print $strScrollerText ?> ">
<input type="text" name="strOldPreviewText" value=" <?php print $strOldPreviewText ?> ">
<input type="submit" name="btnUpdateSubmit" value="Submit" value='Yes/No' onclick='return

confirm("Are you satisfied with the new message?");'>

</form>
</body>
</html>[/code]

[b]Please use the code tags when posting code to the forum.[/b]

Share this post


Link to post
Share on other sites

×

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.