Here is the piece of code that configures the CActiveForm instance.
$wdgRegisterForm = $this->beginWidget('system.web.widgets.CActiveForm', array(
'id'=>'register-account',
'action'=>Yii::app()->urlManager->createUrl($this->id . '/mainContainer.registerAccount'),
'enableAjaxValidation'=>true,
'enableClientValidation'=>true,
'htmlOptions'=>array(
'class'=>'uk-form uk-form-stacked',
'enctype'=>'multipart/form-data'
),
'clientOptions'=>array(
'validationDelay'=>0,
'validateOnSubmit'=>true,
'validateOnChange'=>false,
'hideErrorMessage'=>true,
After this I have some JavaScript validation routines and here comes how the e-mail field is declared:
echo $wdgRegisterForm->textField($this->modelRegister, 'email', array(
'id'=>'txtRegisterEmail',
'class'=>'uk-width-1-1',
'placeholder'=>'Adresa de e-mail')) . PHP_EOL;
?>
echo $wdgRegisterForm->error($this->modelRegister, 'email', array(
'inputID'=>'txtRegisterEmail',
'validateOnChange'=>true,
'validateOnType'=>true
));
There is also a captcha with a captcha field tied to the form model:
$this->widget('system.web.widgets.captcha.CCaptcha', array(
'captchaAction'=>$this->id . '/mainContainer.captcha',
'buttonLabel'=>'Genereaza cod nou',
'buttonOptions'=>array(
'id'=>'btnRegisterNewCaptcha'
),
'imageOptions'=>array(
'id'=>'imgRegisterCaptcha'
),
));
echo $wdgRegisterForm->textField($this->modelRegister, 'verifyCode', array(
'id'=>'txtRegisterCaptcha',
'class'=>'uk-align-left uk-form-width-medium',
'placeholder'=>'Scrie codul din imagine'
));
echo $wdgRegisterForm->error($this->modelRegister, 'verifyCode', array(
'inputID'=>'txtRegisterCaptcha'));
?>
These pieces of code are written in the main layout and modelRegister is an instance of RegisterAccountForm that is instantiated in a behavior attached to the controller.
Here is how RegisterAccountForm looks:
namespace models\forms;
use \Yii;
use \CFormModel;
use \CCaptcha;
use \models\Users;
class RegisterAccountForm extends CFormModel
{
/**
* Model Attributes
*/
public $email;
public $verifyCode;
// validation rules for attributes
public function rules() {
return array(
array('email', 'length', 'allowEmpty'=>false, 'min'=>6, 'max'=>70),
array('email', 'email'),
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements(), 'captchaAction'=>Yii::app()->controller->id . '/mainContainer.captcha')
);
}
}
There is also a lot of HTML code that was stripped.