Forum Moderators: coopster

Message Too Old, No Replies

How to populate a form using cookie info

         

phpguy54

4:31 pm on Mar 13, 2008 (gmt 0)

10+ Year Member



Hey guys,

I have a registration form where people fill their info out submit it and then they can come back to the page, but since I have a cookie, they can click submit without having to fill in their information again.

How would I create an edit info button that sends them back to the regiatration form, with all the fields populated so that they can "edit" their info and re-submit if they want?

Thanks

Receptional Andy

4:35 pm on Mar 13, 2008 (gmt 0)



You can access cookie data via $_COOKIE, e.g.


if (isset($_COOKIE["name"])) {
echo $_COOKIE["name"];
}

phpguy54

4:50 pm on Mar 13, 2008 (gmt 0)

10+ Year Member



Thanks,

I tried that and it leads to a blank page with the cookie information piped together at the top. How do I get the cookie to re-display on a form?

Receptional Andy

10:57 am on Mar 15, 2008 (gmt 0)



Hi phpguy54,

A very basic example would be to echo the cookie value where you call your form:

<input type="text" name="name" value="<?php echo $_COOKIE["name"]; ?>">

Remember that cookie values are user-supplied though, so make sure the data is clean before you print it on the page: at a minimum htmlentities(strip_tags($_COOKIE["name"]));