我有一个问题,我真的无法弄清楚如何解决。我有同一个项目的2个不同页面。它允许用户创建表单并将其提交到不同的网页。还有两个版本,一个只需要字段类型,名称和值,另一个允许用户手动输入完整的表单。完全相同的html,它为什么表现不同?
所以,正如我的问题所述,在第一种情况下,它完美地工作,而在第二种情况下,它回到同一页面,并且它让我疯狂!我将把代码放在最后,但现在要重现错误的步骤。到目前为止,它是免费托管的网页,因为我用它来测试目的:
- 转到http://saveyourself.vacau.com/form/
在田地里将这个(这其实是一个测试帐户此页):
- 页:http://newfutureuniversity.org/
- 方法: “邮报”
- 名称1: “用户”
- 值1: “用户”
- 类型1: “文本”
- 名称2: “通过”
- 值2: “密码”
- 类型3: “密码”
- 名称3: “登录”
- 值3 :“1”
- 类型3:“隐藏”。
按“显示表”,并在窗体将显示
- 现在看到页面的源代码,并从“
<form...>
”复制到“</form>
” - 转到http://saveyourself.vacau.com/form/manual/此页并粘贴在那里。
- 按下“显示表单”,你应该完全到达步骤3后的相同页面(检查html,它是100%相同,唯一的变化是地址/ manual /)。
现在,这是诀窍。尽管两个页面都有完全相同的HTML,但如果在步骤3之后按下“发送表单”按钮,则会登录新页面,但如果在步骤6之后按下“发送表单”按钮(在/ form/manual /),该页面被刷新并且您粘贴的表单被删除。这怎么可能?据我所知,这里没有涉及PHP,因为当表单显示时,它只是简单的html,新页面应该处理整个PHP。所以,如果它收到相同的表格,它应该以同样的方式回答,对吗?在第二页中,它没有使用“$ _SERVER ['HTTP_REFERER'];” (访问者来自哪里),也没有任何类似的东西。此外,还有0个JavaScript。我现在发布html以防它有用,还有一些PHP(不要放太多代码)。
所以问题是,没有人有任何想法,为什么第二种形式不起作用?
非常感谢。
HTML代码(它在两个页面相同的第3步后或6):
<!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>
<title>Send form</title>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
</head>
<body style="background: #DDFFFF; width: 80%; height:100%; margin: 0 10% 0 10%; text-align: center;">
<h1>Send form</h1>
<form action="http://newfutureuniversity.org/" method="POST">
Web page: http://newfutureuniversity.org/<br>
Method: POST<br><br>
<table style="margin-left: auto; margin-right: auto;">
<tr>
<td style="text-align: right;">
User:</td><td><input type='text' name='User' value=''></td>
</tr>
<tr>
<td style="text-align: right;">
Pass:</td><td><input type='password' name='Pass' value=''></td>
</tr>
<tr>
<td style="text-align: right;">
Login:</td><td><input type='text' name='Login' value='1'></td>
</tr>
</table><br>
<input type="submit" value="Send form">
</form>
</body>
</html>
从页面工作简化PHP代码(http://saveyourself.vacau.com/form/):
//Header, body and others go before of this
<?php
if ($_POST['sent']==1&&empty($_POST['source'])) //If form is submited
{
$i = 1;
?>
<form action="<?php echo $_POST['page']; ?>" method="<?php echo $_POST['method']; ?>">
Web page: <?php echo $_POST['page']; ?><br>
Method: <?php echo $_POST['method']; ?><br><br>
<table style="margin-left: auto; margin-right: auto;">
<?php
while (!empty($_POST['nam'.$i]))
{ ?>
<tr>
<td style="text-align: right;">
<?php echo $_POST['nam'.$i].":</td><td><input type='".$_POST['typ'.$i]."' name='".$_POST['nam'.$i]."' value='".$_POST['val'.$i]; ?>'></td>
</tr>
<?php
$i++;
}
?>
</table><br>
<input type="submit" value="Send form">
</form>
<?php
}
elseif (!empty($_POST['source'])) //If user just wants to create a form and see the code
{
//I think this bit is irrelevant codereview, so I skipped it.
}
else //Body of the first page shown
{ ?>
<form method="post">
Web page: <input type="text" name="page">
Method to send: <select name="method"><option value="POST">Post</option><option value="GET">Get</option></select><br>
<table style="border: 1px solid #AAA; margin-left: auto; margin-right: auto;">
<tr>
<td>Number</td>
<td>Name</td>
<td>Value</td>
<td>Type</td>
</tr>
<?php for ($i = 1; $i <= 10; $i++)
{ ?>
<tr>
<td><?php echo $i; ?></td>
<td><input type="text" name="nam<?php echo $i; ?>"></td>
<td><input type="text" name="val<?php echo $i; ?>"></td>
<td>
<select name="typ<?php echo $i; ?>">
<option value="text">Text</option>
<option value="password">Password</option>
<option value="radio">Radio</option>
<option value="checkbox">Checkbox</option>
<option value="hidden">Hidden</option>
<option value="reset">Reset</option>
<option value="submit">Submit</option>
</select>
</td>
</tr>
<?php } ?>
</table><br>
Don't worry, a submit button is automatically added.<br>
<input type="hidden" name="sent" value="1">
<input type="submit" value="Show form">
<input type="submit" name="source" value="Form code">
</form><?php } ?>
</body>
</html>
从页面的完整PHP代码不起作用(http://saveyourself.vacau.com/form/manual/):
<!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>
<title>Send form</title>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
</head>
<body style="background: #DDFFFF; width: 80%; height:100%; margin: 0 10% 0 10%; text-align: center;">
<h1>Send form</h1>
<?php
if ($_POST['sentbrr']==1) //If form is submited
echo stripslashes($_POST['code']);
else //First time
{ ?>
<form method="post">
Enter the code for the form manually<br>
<textarea name="code" style="width: 100%; min-height: 450px;"></textarea><br>
<input type="hidden" name="sentbrr" value="1">
<input type="submit" value="Show form">
</form>
<?php
} ?>
</body>
</html>
您使用的是哪种镀铬版本? – tutuDajuju 2012-02-20 20:30:23
Google Chrome 17.0.963.46将它与Linux一起使用(deb包在Ubuntu 11下运行。10) – 2012-02-21 15:55:22