Reply to How to retain the $_POST variables?

Your name:

Reply:


Posted by damezumari on 05/24/07 16:11

On page a.php I have a form. When it is submitted, the $_POST
variables are validated on page b.php. If something is wrong, page
a.php is shown again with the already filled in field values in place
and an error message or two.

How is this best done? That is, how do I put the already filled in
field values into the form so the user does not have to fill it in
again?

Here is the way I do it. Please suggest better ways!

At the top of a.php I have:
// when called for the first time, or after a successful update, fill
fields with the session variables
if (isset($_SESSION['error'])) // unsuccessful update, so keep the
changes that was made
{
unset($_SESSION['error']);
}
else
{
$_SESSION['parameters']['userfirstname'] =
$_SESSION['userfirstname'];
}

In a.php I have something like this for each text field: (check boxes
and dropdown boxes are a bit different, but that is not essential for
this discussion)
<input type="text" name="userfirstname" value="<?=
$_SESSION['parameters']['userfirstname'];?>" />

At the top of b.php I have:
$_SESSION['parameters'] = $_POST;

If the validation in b.php goes sour:
$_SESSION['error'] = 'empty fields';
$_SESSION['message'] = '<b>Error: Some fields were missing! Please
rectify.</b>';
header('Location: ol_myprofile.php');
die();

Regards,

Jan Nordgreen

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация