phoenixshade
03-07-2007, 04:17 AM
OK, I'm new to php, so this is probably an idiotic oversight, but I swear I've gone over this with a fine tooth comb and can't see what's wrong.
I have a form that submits data to the server with method="post". However, when I hit submit, the superglobal $_POST appears to be empty. I even tried changing to method="get" / $_GET, and not only did I still have the same problem, but the form data didn't even appear in the url!?!
Here's the code. The idea is that it reads the form.html file line-by-line. If form data has been submitted, it is supposed to add a value="value" attribute to any input element. It then displays that line.
register.php
<?php
$lines = file('form.html');
foreach($lines as $line) {
if ($_POST['action']=='sent') {
if (preg_match('/input id=".+?"/', $line, $match)) {
$inputID = substr($match[0],10,strlen($match[0])-11);
preg_match('/type=".+?"/', $line, $match);
$inputType = substr($match[0],6,strlen($match[0])-7);
$insertPoint = strpos($line,'type="');
$insertString = "value=\"$_POST[$inputID]\" ";
$line = substr($line,0,$insertPoint) . $insertString . substr($line,$insertPoint-strlen($line));
}
}
echo $line;
}
?>
form.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Essential Inspirations - Register with www.essential-inspirations.com</title>
<style type="text/css" media="screen, print, projection">
* {
margin: 0;
padding: 0;
}
#wrap {
width: 80%;
margin: 0 auto;
border: solid 2px #530;
}
</style>
</head>
<body>
<div id="wrap">
<form id="register" action="register.php" method="post">
First Name: <input id="fname" type="text" /><br />
Last Name: <input id="lname" type="text" /><br />
Username: <input id="username" type="text" /><br />
Password: <input id="password" type="password" /><br />
Verify Password: <input id="pwverify" type="password" /><br />
e-Mail Address: <input id="email" type="text" /><br />
<input type="hidden" id="action" value="sent" />
<input type="submit" value="submit" /><br />
</form>
</div>
</body>
</html>
Thanks in advance for your help.
I have a form that submits data to the server with method="post". However, when I hit submit, the superglobal $_POST appears to be empty. I even tried changing to method="get" / $_GET, and not only did I still have the same problem, but the form data didn't even appear in the url!?!
Here's the code. The idea is that it reads the form.html file line-by-line. If form data has been submitted, it is supposed to add a value="value" attribute to any input element. It then displays that line.
register.php
<?php
$lines = file('form.html');
foreach($lines as $line) {
if ($_POST['action']=='sent') {
if (preg_match('/input id=".+?"/', $line, $match)) {
$inputID = substr($match[0],10,strlen($match[0])-11);
preg_match('/type=".+?"/', $line, $match);
$inputType = substr($match[0],6,strlen($match[0])-7);
$insertPoint = strpos($line,'type="');
$insertString = "value=\"$_POST[$inputID]\" ";
$line = substr($line,0,$insertPoint) . $insertString . substr($line,$insertPoint-strlen($line));
}
}
echo $line;
}
?>
form.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Essential Inspirations - Register with www.essential-inspirations.com</title>
<style type="text/css" media="screen, print, projection">
* {
margin: 0;
padding: 0;
}
#wrap {
width: 80%;
margin: 0 auto;
border: solid 2px #530;
}
</style>
</head>
<body>
<div id="wrap">
<form id="register" action="register.php" method="post">
First Name: <input id="fname" type="text" /><br />
Last Name: <input id="lname" type="text" /><br />
Username: <input id="username" type="text" /><br />
Password: <input id="password" type="password" /><br />
Verify Password: <input id="pwverify" type="password" /><br />
e-Mail Address: <input id="email" type="text" /><br />
<input type="hidden" id="action" value="sent" />
<input type="submit" value="submit" /><br />
</form>
</div>
</body>
</html>
Thanks in advance for your help.