Hi everyone, I'm new here and this is my first crack at using yii.
I have a form with 4 input fields: firstname, lastname, street and city_state. I also have set up a number of defaults in my model script below to show on the form before users enter data.
class PeopleForm extends CFormModel
{
public $firstname = 'First Name*';
public $lastname = 'Last Name*';
public $street = 'Address';
public $city_state = 'City/State';
public function rules()
{
return array(array('firstname, lastname', 'required'));
}
....................
In my controller I have:
if(Yii::app()->getRequest()->getIsAjaxRequest()) {
echo CActiveForm::validate(array($ppl_model));
Yii::app()->end();
}
if(isset($_POST['PeopleForm'])) {
if ($ppl_model->validate()) {
//Always get's here
}
}
As seen above, I use both ajax and server side validation on my controller. How do I modifiy the rules so that when a user does not enter any text it retruns an error. As it currently is, the form submits the default values for the fields and it passes validation.
I have a form with 4 input fields: firstname, lastname, street and city_state. I also have set up a number of defaults in my model script below to show on the form before users enter data.
class PeopleForm extends CFormModel
{
public $firstname = 'First Name*';
public $lastname = 'Last Name*';
public $street = 'Address';
public $city_state = 'City/State';
public function rules()
{
return array(array('firstname, lastname', 'required'));
}
....................
In my controller I have:
if(Yii::app()->getRequest()->getIsAjaxRequest()) {
echo CActiveForm::validate(array($ppl_model));
Yii::app()->end();
}
if(isset($_POST['PeopleForm'])) {
if ($ppl_model->validate()) {
//Always get's here

}
}
As seen above, I use both ajax and server side validation on my controller. How do I modifiy the rules so that when a user does not enter any text it retruns an error. As it currently is, the form submits the default values for the fields and it passes validation.