Php $\u提交时帖子为空
我有一个注册脚本(称为“script.php”),分为3个步骤;这是基本结构(我已经去掉了一些东西,比如清理用户输入和防止直接访问除1以外的其他步骤):Php $\u提交时帖子为空,php,forms,post,Php,Forms,Post,我有一个注册脚本(称为“script.php”),分为3个步骤;这是基本结构(我已经去掉了一些东西,比如清理用户输入和防止直接访问除1以外的其他步骤): 实数代码: <?php switch ($step) { case 1: //display form $html = <<<FORM <form action="/install?step=2" method="post"> <input
实数代码:
<?php
switch ($step) {
case 1:
//display form
$html = <<<FORM
<form action="/install?step=2" method="post">
<input type="text" name="username">
<input type="email" name="email">
<input type="password" name="password">
<input type="password" name="password_repeat">
<button class="next" type="submit">Next</button>
</form>
FORM;
break;
case 2:
$errors = array();
if (empty($_POST['username'])||!preg_match_all('/^([A-Za-z0-9]+){1,16}$/', $_POST['username'])) {
$errors[] = 'bad/empty username';
}
if (empty($_POST['email'])||!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errors[] = 'bad/empty email';
}
if (empty($_POST['password'])) {
$errors[] = 'empty password';
}
if (empty($_POST['password_repeat'])) {
$errors[] = 'empty password confirm';
}
if ((!empty($_POST['password'])&&!empty($_POST['password_repeat']))&&$_POST['password']!==$_POST['password_repeat']) {
$errors[] = 'passwords do not match';
}
if(count($errors)>0) {
$error_html = 'some errors occurred';
foreach ($errors as $err) {
$error_html .= 'error: '.$err;
}
$form_html = <<<FORM
<form action="/install?step=2" method="post">
<input type="text" name="username" value="{$_POST['username']}">
<input type="email" name="email" id="email" value="{$_POST['email']}">
<input type="password" name="password">
<input type="password" name="password_repeat">
<button class="next" type="submit">Next</button>
</form>
FORM;
$html = $error_html.$form_html;
}
else {
$ent = 'htmlentities';
$html = <<<DATA_OK
<h3>Data overview</h3>
<table>
<tr>
<th>Username:</th>
<td>{$ent($_POST['username'])}</td>
</tr>
<tr>
<th>email:</th>
<td>{$ent($_POST['email'])}</td>
</tr>
<tr>
<th>Password:</th>
<td>{$ent($_POST['password'])}</td>
</tr>
</table>
<form action="/install?step=3" method="post">
<button class="next" type="submit">Avanti</button>
</form>
DATA_OK;
}
break;
case 3:
//connect to db and insert data
break;
}
?>
<!doctype HTML>
<html>
<head>
<title>Script</title>
<meta charset="utf-8">
</head>
<body>
<?php echo $html; ?>
</body>
</html>
剧本
问题是,当我进入第3步时,POST总是空的。步骤2中显示的按钮(如果用户数据良好)是否覆盖了$\u POST?还是因为表单没有输入,只有提交而清空?如何将$\u POST数据传递到步骤3而不使用隐藏字段(因为它们将包含密码/pw哈希)
我在谷歌和这里搜索过,但找不到与我的问题相关的任何东西。
<form action="/install?step=3" method="post">
<button class="next" type="submit">Avanti</button>
</form>
阿凡蒂
您希望在步骤3中发布哪些值?你的表格里没有。甚至按钮也没有名称
属性。表单中具有name属性的字段不会发送空帖子
POST数据的处理方式与隐藏字段相同。发帖子的人可以看到他发的东西,所以没有理由对他隐瞒。如果他发布了步骤1中的密码,他就知道自己发布了什么。您可以将其散列,并将其设置为会话/隐藏字段,即使这是一种不好的做法
一、 真的,我不明白为什么你有两个步骤。如果第二步只有一个按钮,为什么你有它?您可以在步骤1中进行验证,如果可以,请转到步骤3,如果不可以,请继续。为什么要从
$\u GET
中提取值?请发布表单HTML。您的表单是否有method=“post”?@Joe是的,我正在使用休息。我将把它们添加到代码中,我认为它们无关紧要。带有action=“script.php?step=3”
的表单是否包含所有表单字段?数据的概述与实际(隐藏…)字段不同。@PinetreesRecordol最好将整个real switch语句添加到real html输出中,等等,混合使用get和post并没有这样的已知问题,所以可能在代码的其余部分有一些具体的内容,所以这个表单正如我所想的那样覆盖了我的$\ post。在通过步骤2中的数据检查后,如何通过阵列?在那个阶段它不应该是空的,没有?@pinetreesarecool序列化、会话或隐藏字段。数据将不会保留在内存中。这与桌面应用程序不同,桌面应用程序在打开时总是使用内存。每个对新页面或同一页面的请求都会以关闭应用程序并再次打开的方式清除内存。我扩展了我的答案。谢谢你的回答。我有两个(实际上是三个)步骤,因为流程应该是:步骤1:用户输入-->步骤2:输入良好,显示概述。如果用户希望继续-->步骤3:将数据添加到数据库中
<form action="/install?step=3" method="post">
<button class="next" type="submit">Avanti</button>
</form>