Copy link to clipboard
Copied
Hi, I am new to Web programming and Dreamweaver and have spent over a week trying to get the form method POST to work. If I use GET all is well but POST fails. I get an "Undefined index: mytest on line 11 of program aato. Please let me know what am I failing to do?
My configuration is:
HP Laptop Intel 2 Duo 2.66MHz 4GB
Windows 7 Home premium
Dreamweaver CS5
============================= Program aafrom =========================================================
<!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>
<div id="test">
<form id="form1" name="form1" method="post" action="aato.php">
<p>
<label>Input
<input type="text" name="mytest" id="mytest" tabindex="10" />
</label>
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit" tabindex="30" />
</p>
</form>
</div>
</body>
</html>
============================= Program: aato =========================================================
<!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>
<div>
<form id="form1" name="form1" method="post" action="">
<?php $input = $_POST['mytest']; // I have tried $_POST and $_GET with and without a <form ......>
echo $input;
?> </form>
</div>
</body>
</html>
Copy link to clipboard
Copied
Post #6 in the following link explains the error message for undefined variable.
http://forums.adobe.com/thread/841901
What are you trying to do? If you visit page 2 without submitting a form then you'll get that error message. No need for form in page 2. Put it in one page:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>The Shocker</title>
</head>
<body>
<div id="test">
<?php
// start the condition whether the form has been submitted or not
if (isset($_POST['mytest'])) {
// define the $input variable to the value of the mytest form input
$input = $_POST['mytest'];
// display the data on the page
echo $input;
// else display the form if the form has not been submitted
} else {
?>
<form method="post" action="">
<p>
Input <input type="text" name="mytest">
</p>
<p>
<input type="submit" value="Submit">
</p>
</form>
<?php
// end the condition whether the form has been submitted or not
} ?>
</div>
</body>
</html>
Copy link to clipboard
Copied
Hi,
Thank you for answering. I created the two forms as a test because I was unable to get POST to work. The original form was a log in form using "User authentication" -> "Log in user" which will not work with GET. Part of my login needs to pass the primary key to the user's company (populated in a hidden field during the log in procedure). Many other of my forms need to POST data as well so I must get it working. It is such a basic procedure I suspect that there is something simple that needs to be done.
After trying for days, being new to this it took me while to figure out where it was going wrong. The last place I suspected was that POST was not working. Since then I have created more forms trying to use POST and non of them will work but GET does.
I did not want to include a complicated form with this question so I created the two simple ones. The web site I am creating needs to use POST.
Copy link to clipboard
Copied
Actually, your POST form works.I copied the code you provided into two files, named one form1.html and the other aato.php. I made no changes to your code.
Are you running this on a web server? PHP code will only run on a webserver that includes PHP.
However, you should also make note of the code that was recommended to you. Most of the time we post to the same file. This is necessary for good validation, so you can give the visitor the opportuntity to correct mistakes they make on the form without having to start over from scratch.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now