Shahid Karimi
Shahid Karimi

Reputation: 4357

Yii form ajax validation, Submit and response

I think every framework supports some built in AJAX support so it might be a general question regarding MVC based development. What I want to ask is. I have form which submits data via AJAX everything is working fine except that when i submit a form without filling text fields it validates data and the data validation text is getting as response.

I want to avoid this thing not to happen.

Upvotes: 0

Views: 5619

Answers (1)

thaddeusmt
thaddeusmt

Reputation: 15600

Your question is hard to understand (and you have not revised it despite requests to), but I will take a stab at answering ( against my better judgement ;).

You might have two problems:

  1. You don't want to validate with AJAX

If this is the case, looking at your other question you are on the right track as far as I can tell. You can turn off AJAX validation like so:

<?php $form=$this->beginWidget('CActiveForm', array(
  'id'=>'contacts-form',
  'enableAjaxValidation'=>false, // this turns off AJAX validation
)); ?>

With enableAjaxValidation set to false empty text fields will no longer be validated with Yii's built in AJAX validation system.

  1. You don't have the correct field validation rules set on your Model

If you don't want to see errors when submitting blank textfields, then you have an issue with your Model validation rules. It sounds like these fields are set to "required", and you don't want them to be. If this is the case, then even if you turn of AJAX Validation, you will get these errors when you validate your model on the regular non-AJAX submit.

Here is an example:

class Model extends CActiveRecord {
  public function rules() {
    return array(
        array('oneTextField, anotherTextField', 'required'), // these will error if submitted empty / blank
        array('checkboxField', 'boolean'),
    );
  }
}

Here is a good place to start learning about Yii's validation rules for Models: Declaring Validation Rules

Good luck

Upvotes: 2

Related Questions