Re: processing html forms and keeping the values

From: Date: Tue, 24 Nov 2009 17:47:13 +0000
Subject: Re: processing html forms and keeping the values
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-300077@lists.php.net to get a copy of this message
On Tue, Nov 24, 2009 at 06:14:01PM +0100, Merlin Morgenstern wrote: > Hi there, > > I am trying to redirect a user back to a html form if a validation > failes. The form shoult then hold all entered values. So far I did this > over $_GET, but there is a 100 Character limitation. How could I do this > while keeping all characters? > > Thank you for any hint, *Don't* use GET for this. Here's the typical way this is done: If the name of the file is myfile.php, then in the file do this: <form action="myfile.php" action="post"> This makes the form return to itself when the user hits the "Submit" button. Above the actual HTML part of the form, put a check to determine if the form has been filled in, like this: if (!empty($_POST)) { // Form was filled in do_validation(); if (! $valid) { $_SESSION['myform'] = $_POST; } } else { show_the_file_for_the_first_time(); } In the do_validation() step, you validate the form. If there is a problem and you want to re-show the form, you would typically do this for each field: <input type="text" name="first_field" value="<?php echo $_SESSION['myform']['first_field']; ?>" ?> In other words, you store the form values in the $_SESSION array. Paul -- Paul M. Foster

« previous php.general (#300077) next »