Re: [PHP] processing html forms and keeping the values

2009-11-25 Thread Raymond Irving
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 merli...@fastmail.fm
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

Re: [PHP] processing html forms and keeping the values

2009-11-25 Thread Merlin Morgenstern

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 merli...@fastmail.fm
*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



Re: [PHP] processing html forms and keeping the values

2009-11-25 Thread 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 '
form action='.$_SERVER['PHP_SELF'].' method=post
input type=text name=email value='.$_POST['email'].'
input type=submit name=submit value=send form
/form';
}

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



[PHP] processing html forms and keeping the values

2009-11-24 Thread 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: [PHP] processing html forms and keeping the values

2009-11-24 Thread Ashley Sheridan
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




Re: [PHP] processing html forms and keeping the values

2009-11-24 Thread 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: [PHP] processing html forms and keeping the values

2009-11-24 Thread Merlin Morgenstern



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?



Re: [PHP] processing html forms and keeping the values

2009-11-24 Thread 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:

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