View Single Post
  #1 (permalink)  
Old 11-12-2008, 01:15 AM
overflo overflo is offline
WebProWorld New Member
 
Join Date: Nov 2008
Posts: 2
overflo RepRank 0
Default PHP Sticky fields

Hi.I have the following code (a function) to display and process a html form. What I need is for it to have "sticky fields" so that if there is an error and the message is displayed, when they are returned to the form the details that were correctly input are still there.

Code:
function show_page1(){
$action = $_SERVER['PHP_SELF']."?chall=page1";;
		
if(!isset($_POST['submit'])){
$content = "<div id='form'>
			 <form id='form1' name='form1' method='post' action=$action>
			  <table width='303' height='181' border='0'>
			   <tr>
			    <th width='105'>Name:</th>
				<td width='196'><input name='name' type='text' id='name' size='30'  /></td>
			  </tr>
			  <tr>
			   <th width='105'>Suburb:</th>
			   <td width='196'><input name='suburb' type='text' id='suburb' size='30'  /></td>
			  </tr>
			  <tr>
			   <th scope='row'><div align='left'></div></th>
				<td><div align='left'>
				 <input name='submit' type='submit' value='Submit'>
			    </div></td>
			   </tr>
										
			 </table>
			</form>
		   </div>";
}else{
	if($_POST['name']==""){
		$message .="<p>Please enter a name</p>";
	}else{
		$name = mysql_real_escape_string($_POST['name']);
					}
	if($_POST['suburb']==""){
		$message .="<p>Please enter a Suburb</p>";
	}else{
		$name = mysql_real_escape_string($_POST['suburb']);
	}
					
	if(!$message==""){
		$content .=  $message . "<p>Please click <a href=$action>here</a> to go back and try again</p>" ;
	}else{
		//sql insert queries go here
	}
						
}
}
any suggestions greatly appreciated
Reply With Quote