Yiic allows one to easy CRUD, but how do I add validation of the input ?
Yiic allows one to easy CRUD, but how do I add validation of the input ?
Did you read this?
http://www.yiiframew…uide/form.model
It applies to both CFormModel and CActiveRecord.
well… I did read it, but I did not read all the needed infomation about e.g the Email validator… I just assumed that if I added the rule like this:
return array(
array('email','email')
);
then the email was 'required', but I found out that it needs to look like this:
return array(
array('email','email' ,'allowEmpty' => false)
);
or
return array(
array('email' ,'required'),
array('email','email' ,'allowEmpty' => false)
);
IMHO: it would make sense that a validator is ‘enabled’ by default rather than ‘disabled’
The validator design is similar to Prado. The difference is that Yii validator only runs at server side.
The reason that allowEmpty is false by default for email validator (and others) is that we usually only want to see one error message for each input in the error summary. This is similar to that in Prado.
Quote
Why server side only? Would be nice to have it client side too using jQuery as in Prado (if I'm not wrong)…
thanks.
bye,
Giovanni.
Well, this wonders me too. I was expecting Yii to offer client-side validation as well.
Many people do not want/need client side validation and I believe that is why Yii does not have it. You could make an extension for this however I believe. I think client-side validation is over-kill for a framework.
Quote
I guess that this is the answer, anyway I'd like to hear about it from qiang…
thanks.
bye,
Giovanni.