|
Posted by Rich on 09/29/76 11:45
On 20 Apr 2006 01:54:20 -0700, number1.email@gmail.com wrote...
>
>Hello,
>
>I'm having some problems in passing hidden fields from one Web Page to
>another and was wondering if anyone could help me out.
>
>Basically, I have a Web Page (ie: page1.php) with code:
>
>-----------------------------------------------------------------------------------------------------------
>
><html>
><head><title>Test Web Page</title>
><script language="javascript">
>function chkForm(formObj)
>{
> // Validation Scripts will go here...
>}
>
></script>
></head>
><body bgcolor=#ffffff>
><form action="page2.php" method="post" name="myForm"><BR>
>
><form name="myForm" onSubmit="return chkForm(this.form);"
>action="page2.php" method="post">
>
><?php
>error_reporting(E_ALL);
>
>$username = "Sally Jones";
>
>?>
>
><input type="hidden" name="username" value=<?php echo $username; ?> >
>
><hr align='left' width='60%' noshade></tr>
>
><input type="submit" value="Submit Answers" onclick="return
>chkForm(this.form)">
>
></form>
></body>
></html>
>
>-----------------------------------------------------------------------------------------------------------
>
>When the user clicks on "Submit Answers", it calls the following Web
>Page (ie: page2.php) :
>
><HTML>
><HEAD><TITLE>INSERT Data via PHP</TITLE></head>
>
><BODY>
>
><form action="page1.php" method="post">
>
><?PHP
>error_reporting(E_ALL);
>
>echo "Hello: ";
>echo $username;
>?>
><BR><BR>
><input type="submit" value="Want to go back?">
><input type="hidden" name="username" value="<?PHP echo $username; ?>">
></form>
>
></BODY>
></HTML>
>
>-----------------------------------------------------------------------------------------------------------
>
>I'm getting errors on the hidden fields that I'm trying to pass. For
>example, I would expect to see
>
>Hello: Sally Jones
>
>but instead, I get:
>
>Notice: Undefined variable: username in
>/export/home/my/newsite.com/public_html/page2.php on line 12
>
>Can anyone advise me on what is wrong...and how to correct it?
>
>Thanks...
>
In your page2.php program the "$username" variable is undefined since it has no
value. Since you want to capture the value of a form field name "username" and
your form is using the POST method, you can define the value using....
$username = $_POST['username'];
... or replacing the $username variable with $_POST['username'] in the program
Rich
--
Carry Forward Bandwidth! Included In All NewsGuy Accounts!
Don't lose what you don't use! - http://newsguy.com/overview.htm
[Back to original message]
|