You are here: Re: How to retain the $_POST variables? « All PHP « IT news, forums, messages
Re: How to retain the $_POST variables?

Posted by Jeff Johns on 05/25/07 14:47

On May 24, 12:11 pm, damezumari <jannordgr...@gmail.com> wrote:
> 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

You could do this on b.php:

<?php
foreach ($_POST as $k => $v) {
$_SESSION[$k] = $v;
}
?>

on a.php

<input type="text" name="test" id="test" value="$_SESSION['test']" />

Just make sure to clear your session variables accordingly.

 

Navigation:

[Reply to this 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

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