stevengreen22 Posted July 1, 2013 Share Posted July 1, 2013 (edited) Hi all, I've a contact form with a save details option. <div class="ourContactFormElement"> <label for="email"><span class="requiredField">*</span>Your Email:</label> <input type="text" name="email" class="required email" value="<?php echo $_COOKIE["cookieUserEmail"]; ?>"<?php if(isset($_POST['email'])){ echo 'value="', htmlspecialchars($_POST['email'], ENT_QUOTES, 'UTF-8'), '"';} ?> /> </div> Edited July 1, 2013 by stevengreen22 Quote Link to comment https://forums.phpfreaks.com/topic/279751-damn-cookies/ Share on other sites More sharing options...
stevengreen22 Posted July 1, 2013 Author Share Posted July 1, 2013 Hi all, I've a contact form with a save details option. <div class="ourContactFormElement"> <label for="email"><span class="requiredField">*</span>Your Email:</label> <input type="text" name="email" class="required email" value="<?php echo $_COOKIE["cookieUserEmail"]; ?>"<?php if(isset($_POST['email'])){ echo 'value="', htmlspecialchars($_POST['email'], ENT_QUOTES, 'UTF-8'), '"';} ?> /> </div> Issues with formatting in here -.- This works fine...if it's not the first time a user visits the site. This is the mess I get after inspecting with firebug: value="<br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><font face='Arial' size='1' color='#000000'><b>PHP Error Message</b></font></td></tr></table><br /> <b>Notice</b>: Undefined index: cookieUserEmail in <b>/home/a6696695/public_html/contact.php</b> on line <b>231</b><br /> <br><table border='1' cellpadding='2' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center'><tr><td><div align='center'><a href='http://www.000webhost.com/'><font face='Arial' size='1' color='#000000'>Free Web Hosting</font></a></div></td></tr></table>" name="email" style="width: 200px;"> It's a feature that I'd like to keep but I can't find a solution. I tried declaring the cookie variables right at the start to be empty strings but that failed. Am I missing something obvious(again)? Quote Link to comment https://forums.phpfreaks.com/topic/279751-damn-cookies/#findComment-1438776 Share on other sites More sharing options...
insidus Posted July 2, 2013 Share Posted July 2, 2013 Cookies can be a pain when debugging. Cookies that are set on a PHP page, at the start, end or middle cannot be used in that 'load' of the page, to get the client to send cookie data to the server to be processed you will have to do a page reload. Once a cookie has been set in your browser, you either need to create a PHP script to destroy the Cookie, setcookie("user", "Alex Porter", time()-3600); - "time()-3600", or delete the browsers cookie/session data. If you wanted to set a cookie, and use its data straight away, you should either use the variable that you used to set the cookie in the first place within the rest of your code. Set the cookie, for a page reload with header('location: page location'). Or set the data into a session aswell and call that instead. Hope that helps a little. /Insidus Quote Link to comment https://forums.phpfreaks.com/topic/279751-damn-cookies/#findComment-1439116 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.