Jump to content

Recommended Posts


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 by stevengreen22
Link to comment
https://forums.phpfreaks.com/topic/279751-damn-cookies/
Share on other sites


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)? 
Link to comment
https://forums.phpfreaks.com/topic/279751-damn-cookies/#findComment-1438776
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/279751-damn-cookies/#findComment-1439116
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.