nicholaspaul Posted November 10, 2007 Share Posted November 10, 2007 It's a basic form with a script to check required fields (the script is called when SUBMIT is clicked, as opposed to being in the main file itself) but the problem I'm having is that when the page is refreshed because fields are missing, ALL the fields are blank. Is there a simple fix? I can post code and all that, but wondered if this was a common error. Thanks! [i searched and came up emtpy...] Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 10, 2007 Share Posted November 10, 2007 So your saying you want to keep the fields filled in if there is an error and they need to fix something? Your form would look like this <form> <input type="text" name="name" value="<?php if(isset($_POST['name']) echo $_POST['name']; ?>"> </form> Quote Link to comment Share on other sites More sharing options...
nicholaspaul Posted November 11, 2007 Author Share Posted November 11, 2007 Yup that's what I want to do - I'll give it a shot. Quote Link to comment Share on other sites More sharing options...
nicholaspaul Posted November 11, 2007 Author Share Posted November 11, 2007 The existing entry doesn't show up. I even tried an echo to see what value $_POST['name'] had, and it doesnt show up. Here's my original code (minus some content that doesnt affect the code). The page with the form on it: <?php include('../common/topofthepage.inc'); ?> <!-- logo, menu, date --> <div id="content"> <!-- everything goes here --> </div> <!-- end indent --> <div id="columnright"> <!-- menu and contents here --> <p>Payment methods accepted: cheque, Mastercard, Visa, Paypal</p> <? if (isset($message)) { echo '<p class="medredi">Please fill out all required fields.<br><br> You message ',$message, '</p>'; } echo 'Done before - ',$donebefore; //debugging ?> <form action="../formcheck/10hourscheck.php" method="POST" > <input type="hidden" name="subject" value="10 Hours Order "> <span class="largered">*</span><span class="smallred"> required fields</span> <p class="pl">name<span class="largered">*</span><br> <input name="name" size="40"class="pl"type="text"> <br>company <br> <input name="company" size="40"class="pl" > <br>address <span class="largered">*</span><br> <input name="add1" size="40"class="pl" ><br> <input name="add2" size="40"class="pl" > <br>city province/state<span class="largered">*</span><br> <input name="city" size="25" class="pl"> <input name="province" size="13"class="pl"> <br>postal code/zip <span class="largered">*</span><br> <input name="postal" size="20"class="pl" > <br>email <span class="largered">*</span><br> <input name="email" size="40"class="pl" > <br><br>Sign me up for 10 hours of design. I need it for: <div id="lhs"> <p> <input type="checkbox" name="ads"> advertising <br> <input type="checkbox" name="web"> website updates<br> <input type="checkbox" name="pub"> publications<br> </p> </div> <div id="rhs"> <p> <input type="checkbox" name="reg"> regular account<br> <input type="checkbox" name="other"> other<br> </p> </div> <div class="clear"></div> <p> <input type="checkbox" name="understand"><span class="largered">* </span> I understand that ...blah blah blah. </p> <input type="submit" value="Buy" class="orangeb"> </form> </div> <? include('../common/endofpage.inc'); ?> <!-- bottom of page stuff --> 10hoursecheck.php, the code referred to in the above script. <?php if (strlen($_POST['name'])>0) //name set? { $nameset = TRUE; } else { $nameset = FALSE; $message .= ' Name /'; } if (strlen($_POST['add1'])>0) //address1? { $addset = TRUE; } else { $addset = FALSE; $message .= ' Address /'; } if (strlen($_POST['city'])>0) //city? { $city = TRUE; } else { $cityset = FALSE; $message .= ' City /'; } if (strlen($_POST['province'])>0) //province? { $provinceset = TRUE; } else { $provinceset = FALSE; $message .= ' Province /'; } if (strlen($_POST['email'])>0) //email? { $emailset = TRUE; } else { $emailset = FALSE; $message .= ' Email Address/'; } if (strlen($_POST['postal'])>0) //email? { $postalset = TRUE; } else { $postalset = FALSE; $message .= ' Postal Code /'; } if (isset($_POST['understand'])) //understand box checked? { $checkbox = TRUE; } else { $checkbox = FALSE; $message .= ' Check Understand Box /'; } $name= $_POST['name']; $company= $_POST['company']; $add1= $_POST['add1']; $add2= $_POST['add2']; $city= $_POST['city']; $province= $_POST['province']; $email= $_POST['email']; $ads= $_POST['advertising']; $pub= $_POST['pub']; $other=$_POST['other']; $summary= " I may use the time for: "; if (isset($ads)){ $summary = $summary . " Advertising "; } if (isset($web)){ $summary = $summary . " Website "; } if (isset($pub)){ $summary = $summary . " Publishing "; } if (isset($reg)){ $summary = $summary . " RegularAccount "; } $body = 'ORDER: ' .$name .' just ordered 10 Hours of design. / email:' .$email .' / city:' .$city .' ' .$province .' // ' .$summary .' / Comments:' .$comments; if (isset($message)) { header("Location: ../products/inhouse.php"); } else { mail("info@nburmandesign.com", "*payment required* $subject From $name", $body, " From: $email"); header("Location: ../products/payorder.php"); } ?> I hope it's easy to read. I like my code spaced out. Quote Link to comment Share on other sites More sharing options...
Daukan Posted November 11, 2007 Share Posted November 11, 2007 It's because when you redirect to the page with the form you aren't sending the post data with it. You can send them through the url and retrieve them. I personally would put the form and input validation into functions and keep them on the same page. Quote Link to comment Share on other sites More sharing options...
nicholaspaul Posted November 11, 2007 Author Share Posted November 11, 2007 I put the forms and validation on the same page, and it all seems to be working much better, including the values for the fields showing up. Thanks for your help and time, Daukan and pocobueno1388. 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.