Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

remember form values

General discussions related to php

Moderators: macek, egami, gesf

remember form values

Postby milily » Thu Sep 04, 2003 12:57 pm

Hi,

I have several fields in a form. If the user leaves some of the required fields empty. I will forward the user back to the form and let them fill those fields. I want to remember the values the user already input. So they don't need to type it again. I don't want to use cookies or session variables. So what I did is:

<input type="text" name="university" value="<?php echo ((empty($_POST['university'])) ? "" : ($_POST['university']) ) ?>">

and

<input type="text" name="university" value="<?php echo ($_POST['university'] ? $_POST['university'] : "" ) ?>">

But both of them don't work. Did I miss anything? Could anyone tell me how to do this? Thank you.

Helen
milily
New php-forum User
New php-forum User
 
Posts: 8
Joined: Sun Jun 29, 2003 12:39 pm
Location: Michigan, U.S.

Postby tryton » Thu Sep 04, 2003 3:05 pm

Try this:

Code: Select all
// This should be at the beginning of the page
<? $email=$_REQUEST['emailAdd'];?>
...

// And when you re-display your form lower in the page,
// enter this
<input name="emailAdd" type="text" id="emailAdd" size="40" value="<? echo $email; ?>">
User avatar
tryton
New php-forum User
New php-forum User
 
Posts: 49
Joined: Wed Jul 09, 2003 8:25 am
Location: Joze

Postby Joel » Thu Sep 04, 2003 11:22 pm

What tryton has said will do the same thing, except
a) It will remedy if the problem is with the form method
b) An unneccesary variable is created.

The only problem I can think of is with the forwarding back, does this mean you use the header function for a new location?

Try this:

Code: Select all
<input type="text" name="university" value="<?php echo @$_POST['university']; ?>">


This will post any contents of the value and suppress the error if it is not set. I think this maybe cheating a little, but its the simplest way of doing it.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

session

Postby ruturajv » Thu Sep 04, 2003 11:40 pm

Why not use sessions to keep all the information ..?
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby sigix » Fri Sep 05, 2003 4:54 am

why don't you use javascript for the client side checks
so use don't leave any fields empty :idea:
sigix
php-forum Active User
php-forum Active User
 
Posts: 364
Joined: Mon Jul 14, 2003 9:39 pm
Location: /Earth/Xion

Postby milily » Fri Sep 05, 2003 10:35 am

Thank you all for your replies.

The reaseon I don't use session variable is I have too many fields and I don't want to have so many session variables. It will be confusing sometimes. Probably I will use javascript if I cannot find the solution from php.

I tried Tryton's method and tried and Joel's method. Neither of them work in my program.

Yes, I use header to reset the location. Is this a problem? If this is not good, what should I use instead of header? In my code, one file is the form html part, another file is the action php part.

Thank you.

Helen
milily
New php-forum User
New php-forum User
 
Posts: 8
Joined: Sun Jun 29, 2003 12:39 pm
Location: Michigan, U.S.

Postby tryton » Fri Sep 05, 2003 2:56 pm

If you can, show us all the code.
User avatar
tryton
New php-forum User
New php-forum User
 
Posts: 49
Joined: Wed Jul 09, 2003 8:25 am
Location: Joze

Postby Joel » Fri Sep 05, 2003 5:59 pm

I think maybe the the header redirection loses the POST variables. I am not too sure of this though, you could easily test

The way I generally do my errors on forms is this...

display page with form included
send form to php self and if no error from validator then process
if there is errors - display errors and include form again

The form has

Code: Select all
value="<?php echo @$_POST['var']; ?>"
[/code]
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand


Return to PHP General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.