我是 yii 的新手,我正在做一些事情。我在查看页面中有很多表单,我单击提交它检查字段并输入数据库。
但我的问题是,我是否有 5 种不同的表单需要检查验证,并且应该保持与输入另一个表单相同的表单。在视图页面中,我保持活动状态,因为它被重定向到活动形式的页面。如果字段为空并且应该保留在该特定页面中并检查验证,我应该如何停止重定向到活动页面。
在控制器中,我一直这样
if(isset($_POST['myform']))
{
$valid = true;
foreach($_POST as $p)
{
if($p == null)
{
$valid = false;
}
}
if($valid)
{
$model->save();
$this->render('mypage',array('model'=>$model,'model1'=>$model1,'model2'=>$model2,'model3'=>$model3,'model4'=>$model4));
}
}
$valid = true;
foreach($_POST as $p){
if($p == null){
$valid = false;
}
}
if($valid){
$model->save();
$this->redirect('yoururl');
}
试试这个
if(isset($_POST['myform']))
{
if(count($_POST)==count(array_filter($_POST)))
{
$model->save();
$this->render('mypage',array('model'=>$model,'model1'=>$model1,'model2'=>$model2,'model3'=>$model3,'model4'=>$model4));
}
}