processing html forms and keeping the values

processing html forms and keeping the values

am 24.11.2009 18:14:01 von Merlin Morgenstern

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,

Merlin

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

Re: processing html forms and keeping the values

am 24.11.2009 18:28:15 von Ashley Sheridan

--=-PmcL6r9nl5ZaNr/xC5w1
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Tue, 2009-11-24 at 18:14 +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,
>
> Merlin
>


Change the form to post

Thanks,
Ash
http://www.ashleysheridan.co.uk



--=-PmcL6r9nl5ZaNr/xC5w1--

Re: processing html forms and keeping the values

am 24.11.2009 18:30:41 von Shawn McKenzie

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,
>
> Merlin

No need to POST and then redirect, just POST the form to itself. If
validation fails redisplay the form using the $_POST array.

--
Thanks!
-Shawn
http://www.spidean.com

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

Re: processing html forms and keeping the values

am 24.11.2009 18:36:20 von TedD

At 6:14 PM +0100 11/24/09, 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,
>
>Merlin

Merlin:

Hint -- look at $_SESSION[]

Here's an example,

http://webbytedd.com/b1/simple-session/

Just enter "guest" and you'll see the code that makes it work. In
this case, it's just storing 1 in $_SESSIN['ok'], but you can have as
many session variables as you want.

Cheers,

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com

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

Re: processing html forms and keeping the values

am 24.11.2009 18:38:24 von Merlin Morgenstern

--------------030900050105030908030706
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit



Ashley Sheridan wrote:
> On Tue, 2009-11-24 at 18:14 +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,
>>
>> Merlin
>>
>>
>
> Change the form to post
>
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
>
>

This is not so easy. I am doing some checking with php on the values and
if one failes php returns via GET to the form with the help of header
location:

$parameter = "&demo=this";
HEADER("Location:/test.html?error=1".$parameter);
exit;

I would need to change way to many things in order to simply change to post.

Isn't there another way?


--------------030900050105030908030706--

Re: processing html forms and keeping the values

am 24.11.2009 18:47:13 von Paul M Foster

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:



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:



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

Re: processing html forms and keeping the values

am 25.11.2009 15:50:21 von Raymond Irving

--0-1805035061-1259160621=:3596
Content-Type: text/plain; charset=us-ascii

There are a couple of ways that you can do this:

1. Store the post values in the $_SESSION variable then echo them back to the screen. Be careful with this as it can lead to XSS. Strip html, etc
2. Send the post values back to the form as part of the query sting. This solution is limited to the size of the query string (2k). Be careful with XSS


Another solution is to use a framework to handle the post back values. One such framework is called Raxan. Here's an example of what it can do:

http://raxanpdi.com/form-state-example.html

__
Raymond Irving


________________________________
From: Merlin Morgenstern
To: php-general@lists.php.net
Sent: Tue, November 24, 2009 12:14:01 PM
Subject: [PHP] processing html forms and keeping the values

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,

Merlin

-- PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--0-1805035061-1259160621=:3596--

Re: processing html forms and keeping the values

am 25.11.2009 16:01:23 von Merlin Morgenstern

--------------030507000805070800030306
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hello Raymond,

thank you for your hint. I will go with sessions. Thanx for the note
regarding XSS.

Kind regards, merlin

Raymond Irving wrote:
> There are a couple of ways that you can do this:
>
> 1. Store the post values in the $_SESSION variable then echo them back
> to the screen. Be careful with this as it can lead to XSS. Strip html, etc
> 2. Send the post values back to the form as part of the query sting.
> This solution is limited to the size of the query string (2k). Be
> careful with XSS
>
> Another solution is to use a framework to handle the post back values.
> One such framework is called Raxan. Here's an example of what it can do:
>
> http://raxanpdi.com/form-state-example.html
>
> __
> Raymond Irving
> ------------------------------------------------------------ ------------
> *From:* Merlin Morgenstern
> *To:* php-general@lists.php.net
> *Sent:* Tue, November 24, 2009 12:14:01 PM
> *Subject:* [PHP] processing html forms and keeping the values
>
> 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,
>
> Merlin
>
> -- PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--------------030507000805070800030306--

Re: processing html forms and keeping the values

am 25.11.2009 20:18:56 von Kim Madsen

Merlin Morgenstern wrote on 2009-11-24 18:38:

> This is not so easy. I am doing some checking with php on the values and
> if one failes php returns via GET to the form with the help of header
> location:
>
> $parameter = "&demo=this";
> HEADER("Location:/test.html?error=1".$parameter);
> exit;
>
> I would need to change way to many things in order to simply change to
> post.
>
> Isn't there another way?

This is what I normally do with larger forms:

1. create the form as a function: form()
2. submit the form to the same page
3. test relevant input and if the fail print form()

Example:

function form() {
print '



';
}

if($_POST['submit']) {
// test email is entered
if(!$_POST['email']) {
print "error: you must enter an e-mail address";
form();
}
else {
// do stuff from here...
}
}
else
form();

With a 50 field form this is a nice approach for me :-)

--
Kind regards
Kim Emax - masterminds.dk

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