I am using sessions to repopulate values in form,Its look something like this My form have some fields and I want to populate user entered values after sever side validattions.Below is the form:
<html>
<form>
Name: <input type="text" id="name" name="name" value="<?php if(isset($_SESSION['NAME'])) echo $_SESSION['NAME'];?>" >
Address:<input type="text" id="address" name="address" value=<?php if(isset($_SESSION['ADDRESS'])) echo $_SESSION['ADDRESS']; ?>>
</form>
</html>
I am storing the values in action page like this:
<?php
$_SESSION['NAME'] = $strname ;
$_SESSION['ADDRESS'] = $straddress;
?>
want to know whether this is the right way to do it,to populate user entered values after server side validation.Although it works fine.
There is no need to store it in session variables if you need it to use just after you have posted the form. You can either use $_POST or $_GET depending upon the form submission method you use.
Also you can use extract function on $_POST or $_GET to get the posted values using it's field name.