您好,我正在开发注册页面。这就是我的表单的样子:
<form action="/user/reg-link" method="POST">
<input type="text" name="txt_un">
<input type="text name="email">
<input type="submit">
</form>
在我的路线文件中:
$app->get('/user/registration', function() use($app) {
$app->render('registration.html');
});
$app->post('/user/reg-link', function() use($app) {
$request = \Slim\Slim::getInstance()->request()->post();
if($request['txt_un'] == "") {
// $app->redirect back with form still filled up
} else {
echo "good job";
}
});
我想要做的是,如果用户名
字段为空,但电子邮件字段仍必须包含提交之前的值,则重定向回表单。我怎样才能做到这一点?
最佳答案
Slim 框架带有 flash() 模块。您可以添加这些代码
$app->flash('txt_un', $request["txt_un"]);
$app->flash('email', $request["email"]);
$app->redirect(your redirect path);
在您的注册页面中,将您的代码修改为这样
<input type="text" name="txt_un" value="{{flash.txt_un}}">
<input type="text" name="email" value="{{flash.email}}">
关于php - Slim 框架使用 post 值重定向回来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31445185/