Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Model Validation In Rules Function...

$
0
0
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.

Viewing all articles
Browse latest Browse all 18717

Trending Articles