graham23s Posted January 13, 2009 Share Posted January 13, 2009 Hi Guys, i'm re-doing a few forms on my site, i was trying to (when the user submits the data, incase of an error the fields are still filled in) so if your filling the form in, submit it, there is errors all the fields still have the users input in them, i'm not sure how i'd go about this any advice would be great thanks guys Graham Quote Link to comment https://forums.phpfreaks.com/topic/140717-posting-forms-and-keeping-the-values/ Share on other sites More sharing options...
premiso Posted January 13, 2009 Share Posted January 13, 2009 You would want to store the POST data in SESSIONS then if that session variable isset call it on that page. If the form submits right unset the session data you just put in. Let me know if you need a more thorough description. Quote Link to comment https://forums.phpfreaks.com/topic/140717-posting-forms-and-keeping-the-values/#findComment-736526 Share on other sites More sharing options...
graham23s Posted January 13, 2009 Author Share Posted January 13, 2009 Hi P, Please if you could that would be great, if it's any help here the page i'm on: <?php include("inc/inc-sessions.php"); include("inc/inc-dbconnection.php"); include("inc/inc-header.php"); include("inc/inc-online.php"); include("inc/inc-functions.php"); include("inc/inc-countries.php"); ?> <div class="fcp-main-content-area"> <div class="fcp-breadcrumb"> <ul> <li><a href="index.php">Home</a></li> >> <li><a href="javascript:history.go(-1)">Previous Page</a></li> >> <li>Checkout.</li> </ul> </div> <h2>Checkout</h2> <?php // A LITTLE PHP CHECK TO MAKE SURE THE SHIPPING ISN'T 0.00 $qS = "SELECT * FROM `fcp_orders` WHERE `customer_id`='$cusSessionID'"; $rS = mysql_query($qS); while ($aS = mysql_fetch_array($rS)) { $shippingCosts = $aS['shipping_costs']; // ARRAY $shippingArray = array($shippingCosts); foreach($shippingArray as $found) { if ($found == "0.00") { $triggerError = true; } } } ?> <?php if (isset($triggerError)) { print "<p class=\"fcp-message-error\">Your never selected a delivery option on the \"My Cart\" page.</p>"; include("inc/inc-footer.php"); exit; } ?> <?php // GET THE LOGGED IN CUSTOMERS DETAILS $qLC = "SELECT * FROM `fcp_customers` WHERE `id`='$cusSessionID'"; $rLC = mysql_query($qLC); $aLC = mysql_fetch_array($rLC); // VARS $cusFN = $aLC['first_name']; $cusLN = $aLC['last_name']; $cusAD = $aLC['address']; $cusCT = $aLC['city']; $cusSC = $aLC['state_county']; $cusPZ = $aLC['post_zip_code']; $cusCO = $aLC['country']; $cusTP = $aLC['home_number']; ?> <form action="checkout.php" method="POST" name="checkoutForm" onSubmit="return validateCheckoutForm()" /> <table border="0" cellpadding="5" cellspacing="0" /> <tr> <td class="fcp-proceed-checkout-border" colspan="2"><img src="img/img-proceed-checkout.png" alt="Please check your order details below" border="0" /></span></td> </tr> <tr> <td align="left"><h3>Shipping Address</h3></td> </tr> <tr> <td align="left" ><h4><?php print "$cusFN " . "$cusLN"; ?></h4><br /><?php print "$cusAD"; ?><br /><?php print "$cusCT, $cusSC, $cusPZ"; ?><br /><?php print "$cusCO"; ?><br />Phone: <?php print "$cusTP"; ?></td> </tr> <tr> <td colspan="2" class="fcp-sign-up-table-bottom" align="left" ><input type="checkbox" name="fcp-ship-old-address"> <span class="fcp-small-note">(Please tick this box to ship to this address.)</span></td> </tr> <tr> <td align="left"><h3>New Shipping Address</h3></td> </tr> <tr> <td align="left"><span class="Required">*</span> First Name:</td><td align="left"><input type="text" class="txt-standard" name="txt-first-name" id="txt-first-name" /></td> </tr> <tr> <td align="left"><span class="Required">*</span> Last Name:</td><td align="left"><input type="text" class="txt-standard" name="txt-last-name" id="txt-last-name" /></td> </tr> <tr> <td align="left"><span class="Required">*</span> Telephone:</td><td align="left"><input type="text" class="txt-standard" name="txt-telephone" id="txt-telephone" /></td> </tr> <tr> <td align="left"><span class="Required">*</span> Address:</td><td align="left"><input type="text" class="txt-standard" name="txt-address" id="txt-address" /></td> </tr> <tr> <td align="left"><span class="Required">*</span> Suburb/City:</td><td align="left"><input type="text" class="txt-standard" name="txt-suburb-city" id="txt-suburb-city" /></td> </tr> <tr> <td align="left"><span class="Required">*</span> Country:</td><td align="left"><select name="txt-country"> <?php foreach ($countryArray as $cusCountry) { print "<option value=\"$cusCountry\">$cusCountry</option>\n"; } ?> </select></td> <tr> <td align="left"><span class="Required">*</span> State/Province:</td><td align="left"><input type="text" class="txt-standard" name="txt-state-province" id="txt-state-province" /></td> </tr> <tr> <td align="left"><span class="Required">*</span> Zip/Postcode:</td><td align="left"><input type="text" class="txt-standard" name="txt-zip-post-code" id="txt-zip-post-code" /></td> </tr> <tr> <td colspan="2" align="left" ><input type="checkbox" name="fcp-ship-old-address"> <span class="fcp-small-note">(Please tick this box to ship to this address. please note if the country is different we will need to recalculate the shipping cost)</span></td> </tr> <tr> <td class="fcp-sign-up-table-bottom" colspan="2" align="left" ><input type="checkbox" name="fcp-ship-old-address"> <span class="fcp-small-note">(Add this address to my address book.)</span></td> </tr> <tr> <td class="fcp-sign-up-table-bottom" align="left" colspan="2"><input type="submit" name="submit-sign-up" value="Create Account" /></td> </tr> </table> </form> <?php include("inc/inc-footer.php"); ?> So it's done in sessions, i'm beginning to see thanks mate Graham Quote Link to comment https://forums.phpfreaks.com/topic/140717-posting-forms-and-keeping-the-values/#findComment-736528 Share on other sites More sharing options...
premiso Posted January 13, 2009 Share Posted January 13, 2009 If you want to know how to set/unset the session vars I would need to also see the checkout.php page but here is an example for this page <td align="left"><span class="Required">*</span> First Name:</td><td align="left"><input type="text" class="txt-standard" name="txt-first-name" value="<?php echo isset($_SESSION['txt-first-name'])?$_SESSION['txt-first-name']:''; ?>" id="txt-first-name" /></td> Just rinse and repeat for each value you want to carry over. Then the checkout.php you just need to put each of those elements into session if there is an error, if there is no error then you make sure to wipe those session values if there was an error to avoid this form being populated with last forms data. Quote Link to comment https://forums.phpfreaks.com/topic/140717-posting-forms-and-keeping-the-values/#findComment-736531 Share on other sites More sharing options...
graham23s Posted January 13, 2009 Author Share Posted January 13, 2009 Hi Premiso, That page actually is the checkout.php i'm kinda submitting it to itself, is that ok , does the same rules apply? thanks mate Graham Quote Link to comment https://forums.phpfreaks.com/topic/140717-posting-forms-and-keeping-the-values/#findComment-736534 Share on other sites More sharing options...
premiso Posted January 13, 2009 Share Posted January 13, 2009 Hi Premiso, That page actually is the checkout.php i'm kinda submitting it to itself, is that ok , does the same rules apply? thanks mate Graham You could instead replace the $_SESSION with $_POST and no other processing would be required. Quote Link to comment https://forums.phpfreaks.com/topic/140717-posting-forms-and-keeping-the-values/#findComment-736543 Share on other sites More sharing options...
graham23s Posted January 13, 2009 Author Share Posted January 13, 2009 perfect! thanks for that mate. Graham Quote Link to comment https://forums.phpfreaks.com/topic/140717-posting-forms-and-keeping-the-values/#findComment-736545 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.