Here is my rules method:
public function rules() {
$newRules = array(
array('password_verification, valid_from, valid_until', 'required'),
array('password_verification', 'length', 'min'=>6, 'max'=>32),
array('password_verification', 'compare', 'compareAttribute'=>'password'),
array('username, email', 'length', 'min'=>3,'max'=>255),
array('password', 'length','min'=>6, 'max'=>32), array('username, email', 'unique'),
array('email', 'email'), array('id, type, username, password, email, valid_from, valid_until', 'safe'),
);
return array_merge($newRules,parent::rules());
}
And here is my view (fields which give a hard time):
<div class="row">
<?php echo $form->labelEx($user,'password_verification',array('label'=>'Verification mot de passe','class'=>'forsys-label')); ?>
<?php echo $form->passwordField($user,'password_verification',array('size'=>30,'maxlength'=>32)); ?>
<?php echo $form->error($user,'password_verification') ?>
</div>
<div class="row">
<?php echo $form->labelEx($user,'valid_from',array('label'=>'Valide depuis le','class'=>'forsys-label')); ?>
<?php echo $form->dateField($user,'valid_from'); ?>
<?php echo $form->error($user,'valid_from'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($user,'valid_until',array('label'=>"Valide jusqu'au",'class'=>'forsys-label')); ?>
<?php echo $form->dateField($user,'valid_until'); ?>
<?php echo $form->error($user,'valid_until'); ?>
</div>
Some informations:
enableClientValidation and enableAjaxValidation are both at true
datefield is a costum method. It's not where the problem come from (a colleague use it in the same way I use it without this problem).
My Problem:
For "valid_until" and "valid_from" errors are not displayed on the HTML.
If I let "password_verification" empty, when I change the focus an error appears (because of ajaxValidation onChange), but none errors if I let "valid_until" or "valid_from" empty.
But these errors are noticed by Yii, I can see them in firebug if I check the ajax request response.
So if all fields are empty, nothing will be created in DB because of 3 errors, but only one (password_validation) will be displayed.
If any body have an idea, you're welcome :)
Sorry for my approximate english
Thank you for read me, have a good day.
Michaël
You have these attributes marked as "safe" in the last rule. Probably that's the reason. Remove that rule or add a scenario for it (usually attributes are declared as safe on 'search' scenario - e.g. add 'on'=>'search' element to that rule).
Related
I have 2 fields in the form (num1 and num2), sum of which forms variable, entered to the databases (sum), which is required. There are some other required fields .
array('summ ', 'required'),
In other words in order to get this variable I need two of these fields (num1 and num2). Without ajaxom validation I solve this problem by:
if($_POST['num1'] && $_POST['num2']) {
$model->sum = $_POST['num1'] + $_POST['num2'];
} else {
$model->sum='';
}
Here is code of form’s part:
<?php echo $form->labelEx($model, 'bithday', array('class' => 'label_register')); ?>
<input name="num1" type="text" value="">
<input name="num2" type="text" value="">
<?php echo $form->error($model, 'bithday'); ?>
After forwarding ajax request, the response containing error messages. But the error doesn’t appear. Though errors of other required fields appear correctly.
Response comes in form of json, with key and it’s value. (Data about this error is contained here)
How to solve this problem? .
Use the Yii textfield like so:
<?php echo $form->labelEx($model, 'num1', array('class' => 'label_register'));
<?php echo $form->textField($model,'num1'); ?>
<?php echo $form->error($model, 'num1'); ?>
<?php echo $form->labelEx($model, 'num2', array('class' => 'label_register'));
<?php echo $form->textField($model,'num2'); ?>
<?php echo $form->error($model, 'num2'); ?>
And add the properties $num1 and $num2 to your model.
I have a login form in modules which uses a chtml textfield which using jQuery does client side validation but if the user does not exist and enters both fields it redirect to the login url and does not display the error in a modal popup.
I am calling modules login via ajax in main layout. It can be in any page and calls the login perfectly.
but the only thing not WORKING is server side validations if login credentials are wrong. It redirects to the user/login page and not display the server side validation error in the modal window.
<?php echo CHtml::beginForm(); ?>
<div class="row1">
<?php echo CHtml::activeTextField($model,'username',array('placeholder'=>'Username or Email','class'=>'pclas')) ?>
</div>
<div class="row1">
<?php echo CHtml::activePasswordField($model,'password',array('placeholder'=>'Password','class'=>'pclas')) ?>
</div>
<div class="remsub">
<div class="rememberMe1">
<?php echo CHtml::activeCheckBox($model,'rememberMe',array('class'=>"btn1"));echo CHtml::activeLabelEx($model,'rememberMe',array('class'=>"btn1")); ?>
<?php ?>
</div>
<div class="submit1">
<?php echo CHtml::submitButton(UserModule::t("Login"),array('class'=>"btn")); ?>
</div>
<div class="regpwd">
<?php echo CHtml::link(UserModule::t("Register"),Yii::app()->getModule('user')->registrationUrl,array('class'=>'pclas1')); ?> | <?php echo CHtml::link(UserModule::t("Lost Password?"),Yii::app()->getModule('user')->recoveryUrl,array('class'=>'pclas1')); ?>
< /div>
</div>
<?php echo CHtml::endForm(); ?>
<?php
$form = new CForm(array(
'elements'=>array(
'username'=>array(
'type'=>'text',
'maxlength'=>32,
),
'password'=>array(
'type'=>'password',
'maxlength'=>32,
),
'rememberMe'=>array(
'type'=>'checkbox',
)
),
'buttons'=>array(
'login'=>array(
'type'=>'submit',
'label'=>'Login',
),
),
), $model);
?>
and its a LOGIN FORM AND NOT A SIGN UP FORM is what my need is possible or any ohter solutions would be appreciated
Yes, please add your code so that we know what you're up to.
Some things that could help:
Perhaps users who are using the form are not allowed to access the controller/action that does the validation? That would cause Yii to redirect him/her to login page. Try looking at the permissions for the controller/action that does the validation.
Make sure your forms have enabled ajax validation:
<?php $form = $this->beginWidget('CActiveForm', array(
'id'=>'user-form',
'enableAjaxValidation'=>true, <----------
'enableClientValidation'=>true,
'focus'=>array($model,'firstName'),
)); ?>
I'm new in drupal 7, and I have to work on an existing project
i want to display a validation message of a webform.
In my custom node.tpl i have a webform with a unique validation on the email, but it's don't show any error message.
I think it was stored in "$messages", but nope.
How can i do this ?
Thanks.
Wow that was easy, but so hard to fine ...
so here is my solution :
<ul style="color:red;">
<?php
foreach (form_get_errors() as $key => $value) {
?>
<li>
<?= $value ?>
</li>
<?php
}
?>
</ul>
<?php
In my form I want to make an ajax validation for the radio buttons of gender.
I have an attribute gender in the model users, at the rules of model I put gender as a required field, but when I submit the form without selecting any gender the validation doesn't work to tell me that the gender cannot be blank, here is my code:
<div class="row">
<?php echo $form->labelEx($model,'gender'); ?>
<?php echo $form->radioButton($model,'gender',array('value'=>'0')) . 'Male<br>'; ?>
<?php echo $form->radioButton($model,'gender',array('value'=>'1')) . 'Female'; ?>
<?php echo $form->error($model,'gender'); ?>
</div>
You should be using radioButtonList() instead of radioButton().
<?php echo $form->labelEx($model,'gender'); ?>
<?php echo $form->radioButtonList($model,'gender',array('1'=>'Male','2'=>'Female')); ?>
<?php echo $form->error($model,'gender'); ?>
I have the following form:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'new-agenda-entry',
'enableAjaxValidation'=>true,
'action'=>'')); ?>
<div class="four columns">
<div class="right top5 sufix10">
<?php echo $form->labelEx($model,'eventTime'); ?>
<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'UserAgenda[eventTime]',
'model'=>$model,
'options'=>array(
'dateFormat'=>'yy-mm-dd',
'minDate'=>'new Date()',
) // jquery plugin options
));?>
<?php echo $form->error($model, 'eventTime'); ?>
</div>
<div class="right top5 sufix10">
<?php echo CHtml::dropdownList('eventTime_hour', false, $this->getHourArray()); ?>
<?php echo CHtml::dropdownList('eventTime_min', false, array('00'=>'00', '30'=>'30')); ?>
</div>
<?php echo $form->labelEx($model,'note'); ?>
<?php echo $form->textField($model, 'note');?>
<?php echo $form->error($model, 'note'); ?>
The model is successfully validated on the server as I can see the response in Firebug:
{"UserAgenda_eventTime":["Event time cannot be blank."],"UserAgenda_note":["Note cannot be blank."]}
The message seems fine, so does the html but the hidden inputs generated by yii remain hidden and empty.
in the action maybe (create or update) you have to uncomment // $this->performAjaxValidation($model); like this you have an ajax validation, if the problem persist I think posting it to yiibootstrap discussion in yii forums i better, I see that you use yiibootstrap, try it with default yii form widget.