Jump to content

Dropped form data


Monkling

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.