PDA

View Full Version : hidden fields n forms


sarah
03-24-2003, 03:45 PM
Hey All, (I know its beens awhile - not been too well but feelin much better now)

Okay, I've designed a form where a user enters in their personal details, i.e first name, surname, addy 1, etc. (easy part this is i know!).

<form name="personal1" action="form2.html">
Surname: <input type="text" name="surname" value="">
Forename: <input type="text" name="forename" value="">
......
etc etc...

<input type="submit" name="Submit" value="Submit">
</form>

On sumbitting the form the user is directed to another page with another form (form2.html)

<form name="personal2" action="confirm.html">
Hair color:<input type="text" name="haircolor" value="">
Eye Color:<input type="text" name="eyecolor" value="">
Age:<input type="text" name="age" value="">
Sex:<input type="text" name="sex" value="">
Location:<input type="text" name="location" value="">
......
etc etc...

<input type="submit" name="Submit" value="Submit">
</form>

The problem I am having is displaying the details from the first form (personal1) on the confirmation.html. I searched the forum and there was something about hidden fields, but I'm not sure on the syntax and how to use them.

Any pointers???
Thnx

arnyinc
03-24-2003, 04:09 PM
The basic setup of a hidden field is similar to a text field. You just change the type and then it doesn't show up.

<input type="hidden" name="age" value="22">

This is one of the things that I prefer to do in a server side language rather than passing data in javascript. That gets too messy for my tastes.

sarah
03-24-2003, 04:18 PM
Hi Arnyinc,

How do I assign the hidden field a value from the form?
i.e:

If I want to set the hidden surname field with the value of surname a user enters on the form.

Any ideas how do I do this?
Sarah

sarah
03-25-2003, 02:56 PM
Hey

How do I pass text fields on from one form to another, and can i store these values?

I.e the equiv in php would be:

<?php

if (isset($HTTP_POST_VARS["surname"])) {
$surname=$HTTP_POST_VARS["surname"];
}


then in my form all i would do is:

<form>
<input type="hidden" name="surname" value="<?php echo $surname; ?> ">

.....
</form>

Then if I need to use the value of $surname, all I do is <? echo $surname; ?>
But I'm not sure of what the equivalent would be in JS. I know someone's thinking why am I not doing this in PHP, answer is I need to this to be in JS.

Any ideas?
Sarah

glenngv
03-26-2003, 06:16 AM
so why not making your action pages in php? it's easy to pass information across pages using server-side language, be it via GET or POST method. You can only pass info via GET using javascript. Here is a script for that: http://codingforums.com/showthread.php?s=&threadid=11802

sarah
03-26-2003, 04:48 PM
Kool Stuff Glenv,

Thanx, I'll giv it a try