Jump to content


Photo

Disappearing values


  • Please log in to reply
2 replies to this topic

#1 w3sl3y2003

w3sl3y2003
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 22 August 2006 - 07:24 AM

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.
Before submit
<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>

After submit
<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?

#2 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 22 August 2006 - 09:06 AM

You haven't posted any of your PHP code here.  Help us to help you  ;)

Regards
Rich
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#3 w3sl3y2003

w3sl3y2003
  • Members
  • PipPip
  • Member
  • 18 posts

Posted 22 August 2006 - 09:21 AM

okay HuggieBear,

frmSubmit.php

<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>

frmUpdate.php

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

Please use the code tags when posting code to the forum.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users