Jump to content

Archived

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

Monkling

Dropped form data

Recommended Posts

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 [i]were [/i]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:
[code]<?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>   
[/code]
I'm at a loss as to why it's chopping up the data.

Share this post


Link to post
Share on other sites
You don't have quotes around the value on the following lines:
[code]<?php echo "<input type=\"text\" name=\"customer\" size=\"50\" style=\"background-color: yellow;\" value=$customer>";?>[/code]
[code]<?php echo "<input type=\"text\" name=\"customer\" size=\"60\" value=$customer>"; } ?>[/code]
[code]<?php echo "<input type=\"text\" name=\"city\" size=\"60\" style=\"background-color: yellow;\" value=$city>";?>[/code]
[code]<?php echo "<input type=\"text\" name=\"city\" size=\"60\" value=$city>"; } ?>[/code]

All attribute values in forms must be quoted.

Ken

Share this post


Link to post
Share on other sites
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.

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.