Reputation: 11
I am new to Yii and have created a form in pure HTML code
Here TesterUserReg is the different controller..
<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="[email protected]"/>
</p>
................. ...............
Sign up
and validating the form by using jQuery validation engine plugin..
and my controller looks like
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,
));
}
When Im submitting the form it renders to Yii default Login page. Its not calling this controller. Please help me to come out of this problem.
Thanks.
Upvotes: 1
Views: 1955
Reputation: 1058
You problem is in your form because in your controller you are trying to get
if(isset($_POST['TesterUserReg']))
Which is never coming from your form then how your form will be processed in your controller.
So what exactly you have to do is change the name of all form inputs as i have mentioned
<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="[email protected]"/>
</p>
By changing the form input names in this manner your controller condition
if(isset($_POST['TesterUserReg']))
will be satisfied and your further process will go on.
Happy Coding :)
Upvotes: 1
Reputation: 1099
It is not regarding about your form whether is using or not using CHtml or CActiveForm. it is your controller problem, please check your filter and accessRules inside your Controller.
If you are not sure about what does that do, you can remove it temporarily, and test whether you still face this problem or not.
Learn more? Check out the following link. Some people do suggest beginers read through the Guide before they get their hands dirty. Yii team do maintain a great documentation. Once you have problem on coding you can simply check out the guide or Class Reference, and you'll find out what you need. http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#filter
Happy coding ^_^
Upvotes: 1