I am looking for a way to keep form values after submit with cookies (after going to page2 and going back to page_form). I am really trying but i need you help guys.
I tried this but it didn't work
<? php
if (isset($_POST['Infos_test']))
{
$expire = 8*3600;
setcookie("Infos_test", $_POST['from']&|&$_POST['area_html'], time()+$expire);
}
?>
.....
<?php
if (isset($_COOKIE['Infos_test']))
{
$Infos_test = explode("&|&", $_COOKIE['Infos_test']);
}
?>
.....
<input type="text" name="from" style="width:350px" value="<?php echo $Info_test[0]; ?>"/>
<textarea valign="top" name="area_html" style="width:350px; height:150px; resize:none;" /><?php echo $Info_test[1]; ?></textarea>
You can save form values in the php session using
$_SESSION
variable and not the cookies.here are several tutorials which help you to do this.
session_php 1 session_php 2
Just copy and paste this code in
test.php
and run & refresh it.. you will understant how it worked.I prefer using SESSION variables before cookies. Here is an example code:
On the form recieving page:
Then on your other page:
Note that the
session_start();
part must be stated BEFORE any other HTML output.HTML syntax for form should read:
Note the type of the INPUT tag and the change how values should be inserted into a TEXTAREA.