Multi Page Forms

Hidden fields not carrying value

Page 1 of 1

7 Replies - 1542 Views - Last Post: 25 January 2010 - 08:42 PM Rate Topic: -----

#1 T-m.S  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 23-January 10

Multi Page Forms

Posted 23 January 2010 - 11:45 PM

I am attempting to make a multi page form.

Using the post method.

The first form is processed by the second page.

the first form (excerpt only)

<form id="form1" name="form1" method="post" action="assessment_form_2.php">

 <input type="text" name="first_name" id="first_name" />



in the second form i have used

  <input type="hidden" name="first_name" value="<?php echo $_POST['first_name'];?>" />



The first page works and sends me on to the second form but when I check the source code the hidden field's value remains empty.

Is this not a valid way of transporting the information?

Is This A Good Question/Topic? 0
  • +

Replies To: Multi Page Forms

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Multi Page Forms

Posted 23 January 2010 - 11:54 PM

Are you certain that there is data in the POST value?
<?php
if($_POST['first_name']!="") { 
  $fn=$_POST['first_name'];
} 
else {
  $fn="empty";
}
 ?>
<input type="hidden" name="first_name" value="<?php echo $fn; ?>" />


Was This Post Helpful? 0
  • +
  • -

#3 T-m.S  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 23-January 10

Re: Multi Page Forms

Posted 24 January 2010 - 12:08 AM

View Postno2pencil, on 23 Jan, 2010 - 10:54 PM, said:

Are you certain that there is data in the POST value?
<?php
if($_POST['first_name']!="") { 
  $fn=$_POST['first_name'];
} 
else {
  $fn="empty";
}
 ?>
<input type="hidden" name="first_name" value="<?php echo $fn; ?>" />



Thank you for replying so quickly.

Yes there is definitely data entered.

I changed my code to your code.

When I viewed the source code there was one change:

instead of value="", I now have value="empty"

I'm at a bit of a loss as to why the information isn't being passed on.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Multi Page Forms

Posted 25 January 2010 - 10:57 AM

View PostT-m.S, on 24 Jan, 2010 - 01:08 AM, said:

I'm at a bit of a loss as to why the information isn't being passed on.

Without seeing the rest of your code, there really is no way we can trouble shoot it for you.
Was This Post Helpful? 0
  • +
  • -

#5 T-m.S  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 23-January 10

Re: Multi Page Forms

Posted 25 January 2010 - 07:27 PM

View Postno2pencil, on 25 Jan, 2010 - 09:57 AM, said:

View PostT-m.S, on 24 Jan, 2010 - 01:08 AM, said:

I'm at a bit of a loss as to why the information isn't being passed on.

Without seeing the rest of your code, there really is no way we can trouble shoot it for you.


I pulled it right back to pure simplicity to test and now I have:

First form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form name="form_1.php" action="form_2.php" method="post"/>
<input type="text" name="first_name" />
<input type="submit" value="submit" />
</form>
</body>
</html>


Second form:
<?php
$first_name = $_POST['first_name'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php 
{ echo "$first_name";
}
?>
<form name="form_2" action="form_3.php" method="post"/>
<input type="hidden" value="<?php echo $_POST['first_name'];?>"/>
<input type="submit" value="submit"/>
</form>
<body>
</body>
</html>



Third form:
<?php
$first_name = $_POST['first_name'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php { 
echo "$first_name";
}
?>
</body>
</html>



When I submit the first form it takes me to the second, it is able to print the $first_name so I know that data is entered and carried but when I check the source code the hidden field is empty. When I submit the second form it takes me to the third page which is blank.

I have obviously completely misunderstood the use of hidden fields but don't know where to start to fix the error.

Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Multi Page Forms

Posted 25 January 2010 - 08:19 PM

When looking at the HTML that your php code creates... take a look at the hidden input. What do you see missing?

test<form name="form_2" action="form_3.php" method="post"/>
<input type="hidden" value="test"/>



Think about it... $_POST gets the variables value from the input field. How are the input fields unique? How does $_POST know which value it's getting from which field? That's right. By the name value. What is missing from your hidden filed? That's right... the name value.

here is a working example

form_2
<?php
$first_name = $_POST['first_name'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-t
ransitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
{ echo "$first_name";
}
?>
<form name="form_2" action="form_3.php" method="post"/>
<input type="hidden" name="first_name" value="<?php echo $_POST['first_name'];?>"/>
<input type="submit" value="submit"/>
</form>
<body>
</body>
</html>



form_3
<?php
$first_name = $_POST['first_name'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-t
ransitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php {
if(!isset($_POST['first_name'])) {
  $first_name=$_POST['first_name'];
}
echo "$first_name";
}
?>
</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#7 T-m.S  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 23-January 10

Re: Multi Page Forms

Posted 25 January 2010 - 08:35 PM

Thank you, that was very easy to follow and understand - silly mistake really. I now have the value being passed to the third page which is all I need.

As a point of understanding though, I was under the impression that I would be able to see the value of a hidden field in the source code yet when i look at the source code for the second page of the form while the hidden field is there the value ="" -

Is this right?
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Multi Page Forms

Posted 25 January 2010 - 08:42 PM

No, that's not correct.

You are giving the hidden value more magic than it deserves.

When you want a user to type in a field, you have an input type of text. Right? & how do you get that data to the form? You reference it by the input name. So why would a hidden field be all magical & automatic? It's not. You are simply taking an input text box, & changing text to hidden to indicate that it's still input, but the value is pre-set & hidden from the visible page. Don't give the hidden input box any more merit than it's suppose to have :)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1