我有一个问题,我真的无法弄清楚如何解决.我有2个不同页面的同一个项目.它允许用户创建表单并将其提交到不同的网页.有两个版本,一个只是请求字段类型,名称和值,另一个允许用户手动输入完整表单.
因此,正如我的问题所述,在第一种情况下它完美地工作,而在第二种情况下它会回到同一页面,这让我发疯!我将代码放在最后,但现在重现错误的步骤.到目前为止,这是一个免费托管的页面,因为我正在使用它进行测试:
把它放在字段中(这实际上是这个页面的测试帐户):
按"显示表格",将显示表格
<form...>" 复制到" </form>"现在,这是诀窍.尽管两个页面都有完全相同的html,如果在步骤3之后按"发送表单"按钮,您将登录到新页面,但是如果您在步骤6之后按下"发送表单"按钮(在/表单/手册中) /),刷新该页面并删除您粘贴的表单.这怎么可能?据我所知,这里没有涉及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>
Run Code Online (Sandbox Code Playgroud)
来自页面工作的简化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>
Run Code Online (Sandbox Code Playgroud)
页面中的完整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>
Run Code Online (Sandbox Code Playgroud)
如果你看第二个(不工作)页面,你有:
<form method="post">
Run Code Online (Sandbox Code Playgroud)
没有action=""附加属性.因此,您的表单不知道将表单提交到哪里.
| 归档时间: |
|
| 查看次数: |
719 次 |
| 最近记录: |