Re: processing html forms and keeping the values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux