Jump to content


Photo

Dropped form data


  • Please log in to reply
2 replies to this topic

#1 Monkling

Monkling
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 September 2006 - 03:17 AM

Forgive me if this is a repeat question but I've searched with no success.

I'm working on a simple form that checks to make sure all the required fields are completed and then presents a form to be printed out. Everything works with one glitch - when the form goes back because the user left out a field, the ones that were completed lose any data following a space. For example, if they fill out their first and last name, when the form is returned, it will only contain their first name.

This is a scaled down version of what I'm doing:
<?php

$counter = (int) $_POST['counter'];
$counter++;

$br="<br>";

$customer=$_POST[customer];	 		
$customer=strip_tags($customer);	

$city=$_POST[city];							
$city=strip_tags($city);	


if
(  ($counter!=1) && ($customer!="") &&   ($city!="")   )
		{						
	echo  $customer.$br.$city;		
	exit;
		}              
?>

<p>  Order Form </p>

<?php
echo "<form name=\"orderform\"  action='" .$_SERVER['SELF'] ."' method='post'>";
 ?>

 <input type="hidden" name="counter" value="<?php print $counter ?>" />
  
 <?php
 if ($counter>1) {
 echo "<p style=\"text-align: center; font-weight: bold; color: red;\">";
  echo "Please complete the highlighted fields</p>";
 }
 ?>
	
 <p style="margin-left: 50px;"><b><u>Ship to: </u></b></p>  
<p>
Name: &nbsp; 
              
<?php 
				
	if (($counter>1) && ($customer==""))
	{ 
	echo "<input type=\"text\" name=\"customer\" size=\"50\" style=\"background-color: yellow;\" value=$customer>"; 
		}
	else {
	echo "<input type=\"text\" name=\"customer\" size=\"60\" value=$customer>"; } ?>			   
	 </p>
 
   <p>City:  &nbsp; 
               
	<?php 
				
	if (($counter>1) && ($addr1==""))
	{ 
	echo "<input type=\"text\" name=\"city\" size=\"60\" style=\"background-color: yellow;\" value=$city>"; 
				}
	else {
	echo "<input type=\"text\" name=\"city\" size=\"60\" value=$city>"; } ?>			   
	
   <p align="center"> 
   <input type="submit" value="View Order Form"  /> 
   &nbsp; &nbsp; &nbsp;    <input type="reset" value="Clear Form" ></p>
         
   </form>     
I'm at a loss as to why it's chopping up the data.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 12 September 2006 - 05:36 AM

You don't have quotes around the value on the following lines:
<?php echo "<input type=\"text\" name=\"customer\" size=\"50\" style=\"background-color: yellow;\" value=$customer>";?>
<?php echo "<input type=\"text\" name=\"customer\" size=\"60\" value=$customer>"; } ?>
<?php echo "<input type=\"text\" name=\"city\" size=\"60\" style=\"background-color: yellow;\" value=$city>";?>
<?php echo "<input type=\"text\" name=\"city\" size=\"60\" value=$city>"; } ?>

All attribute values in forms must be quoted.

Ken

#3 Monkling

Monkling
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 12 September 2006 - 11:47 AM

In a way, I guess it's encouraging to know that my mistakes are usually little, stupid ones staring me right in the face and not huge ones. :D

Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users