Monkling Posted September 12, 2006 Share Posted September 12, 2006 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><?phpecho "<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: <?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: <?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" /> <input type="reset" value="Clear Form" ></p> </form> [/code]I'm at a loss as to why it's chopping up the data. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 12, 2006 Share Posted September 12, 2006 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 Quote Link to comment Share on other sites More sharing options...
Monkling Posted September 12, 2006 Author Share Posted September 12, 2006 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. :DThanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.