只是一些背景。我正在使用 MVC。我的表单放在模板中的 div 中。它发布到我的控制器使用 isset() 捕获它的同一页面,将内容保存到数据库,并重定向到欢迎页面。
编辑:如果我删除表单的操作部分,它会发布所有内容。必须与 index.php 重新路由它的方式有关,以确保用户有权访问该 URL 等。仍在寻找解决方案。
我做了一些调试,很明显变量没有出现在 $_POST 变量中。
<form method="post" action="<?php echo BASE_URL; ?>/login/register">
<fieldset><legend>Person Info</legend>
<table>
<tr><td><label for="firstname" class="required">Firstname:</label></td>
<td><input name="firstname" id="firstname" type="text" value="<?php echo $firstname; ?>" /></td>
</tr>
<tr><td><label for="lastname" class="required">Lastname:</label></td>
<td><input name="lastname" id="lastname" type="text" value="<?php echo $lastname; ?>" /></td>
</tr>
<tr><td><label for="email">Email:</label></td>
<td><input name="email" id="email" type="text" value="<?php echo $email; ?>" /></td>
</tr>
<tr><td><label for="username" class="required">Username: </label></td>
<td><input name="username" id="username" type="text" value="<?php echo $username; ?>" /></td>
</tr>
<tr><td><label for="password" class="required">Password:</label></td>
<td><input name="password" id="password" type="password" value="<?php echo $password; ?>" /></td>
</tr>
<tr><td><label for="pass2" class="required">Confirm:</label></td>
<td><input name="pass2" id="pass2" type="password" value="<?php echo $pass2; ?>" /></td>
</tr>
</table>
<button type="submit" class="btn btn-custom-lighten">Submit</button>
<button type="button" class="btn"
onClick="parent.location='<?php echo BASE_URL; ?>/nonprofit/welcome'">
Cancel
</button>
<br>
<br>
<button type="button" class="btn btn-primary"
onClick="parent.location='<?php echo BASE_URL; ?>/nonprofits/register'">
Nonprofits Register Form
</button>
<br>
</fieldset>
</form>
你可以从控制器代码中看到我的名字是一致的。
public function register()
{
print_r($_POST);
if (isset($_POST['firstname'])) {
try {
$person = new Person();
$person->handleUpdate($_POST);
$person->setUsername($_POST['username']);
$person->setPassword($_POST['password']);
$person->save();
header('Location: '.BASE_URL.'/login/welcome');
exit();
}
catch (Exception $e) {
$_SESSION['errorMessages'][] = $e;
}
}
$this->template->blocks['content'][] = new Block('registerForm.inc',array('return_url'=>$this->return_url));
}
任何帮助将不胜感激,但这似乎是我的表格的问题。我的表单确实被渲染了,只是没有提交。