我是Yii的新手,已经用纯HTML代码创建了一个表单
这里的TesterUserReg是不同的控制器。。
<form id="signup" action="/xyzApp/index.php?r=testerUserReg/create" method="post" accept-charser="UTF-8">
<fieldset>
<div id='solidLine'>
<p>
<label for="name">Name</label><br>
<input id="name" name="username" type="text" class="validate[required,custom[onlyLetter],length[0,100]] text" value="" placeholder="your full name"/>
</p>
<p>
<label for="email">Email</label><br>
<input id="email" name="email" type="text" class="validate[required,custom[email]] text" value="" placeholder="hello@testunity.com"/>
</p>
。。。。。。。。。。。。。。。
注册
并使用jQuery验证引擎插件验证表单。。
我的控制器看起来像
public function actionCreate()
{
$model=new TesterUserReg;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['TesterUserReg']))
{
$model->attributes=$_POST['TesterUserReg'];
$request = Yii::app()->getRequest();
//$model->ut = $request->getPost('username');
$model->ut_pwd = $request->getPost('password');
$model->ut_email_id = $request->getPost('email');
$model->ut_user_id = md5(uniqid(rand(), true));
$model->ut_reg_date = new DateTime();
if($model->save()){}
//$this->redirect(array('view','id'=>$model->ut_user_id));
}
$this->render('create',array(
'model'=>$model,
));
}
当我提交表单时,它会呈现到Yii默认登录页面。它没有调用这个控制器。请帮我解决这个问题。
谢谢。
这与表单是否使用CHtml或CActiveForm无关。这是您的控制器问题,请检查您的控制器中的筛选器和accessRules。
如果你不确定它的作用,你可以暂时删除它,并测试你是否仍然面临这个问题。
了解更多信息?查看以下链接。有些人确实建议乞丐在弄脏手之前先阅读指南。Yii团队确实维护了一份很棒的文档。一旦你在编码上有问题,你可以简单地查看指南或类参考,你就会发现你需要什么。http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#filter
快乐编码^_^
您的表单中存在问题,因为在控制器中您正试图获得
if(isset($_POST['TesterUserReg']))
它永远不会来自你的表单,那么你的表单将如何在你的控制器中处理。
所以,正如我提到的,你要做的是更改所有表单输入的名称
<form id="signup" action="/xyzApp/index.php?r=testerUserReg/create" method="post" accept-charser="UTF-8">
<fieldset>
<div id='solidLine'>
<p>
<label for="name">Name</label><br>
<input id="name" name="TesterUserReg[username]" type="text" class="validate[required,custom[onlyLetter],length[0,100]] text" value="" placeholder="your full name"/>
</p>
<p>
<label for="email">Email</label><br>
<input id="email" name="TesterUserReg[email]" type="text" class="validate[required,custom[email]] text" value="" placeholder="hello@testunity.com"/>
</p>
通过以这种方式更改表单输入名称,您的控制器条件
if(isset($_POST['TesterUserReg']))
将得到满足,您的进一步流程将继续。
快乐编码:)