Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:53:49+00:00 2026-05-30T16:53:49+00:00

I want to validate my form with Ajax Validation method.So for I have made

  • 0

I want to validate my form with Ajax Validation method.So for I have made changes the code for view file like this.

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'customers-form',
        'enableAjaxValidation'=>true,
        'enableClientValidation'=>true,
        'focus'=>array($model,'firstname,lastname,gender,email,contact_no,address,state,country'),
)); ?>

  <p class="note">Fields with <span class="required">*</span> are required.</p>

  <?php echo $form->errorSummary($model); ?>
  <div class="row">
    <?php echo $form->labelEx($model,'firstname'); ?>
    <?php echo $form->textField($model,'firstname',array('size'=>60,'maxlength'=>80)); ?>
    <?php echo $form->error($model,'firstname'); ?>
  </div>

  <div class="row">
    <?php echo $form->labelEx($model,'lastname'); ?>
    <?php echo $form->textField($model,'lastname',array('size'=>60,'maxlength'=>80)); ?>
    <?php echo $form->error($model,'lastname'); ?>
  </div>

  <div class="row">
    <?php echo $form->labelEx($model,'gender'); ?>
    <?php echo $form->radioButtonList($model,'gender',array('Male'=>'Male','Female'=>'Female'),array(
      'labelOptions'=>array('style'=>'display:inline;padding-right:10px'),'separator'=>'',));?>
    <?php echo $form->error($model,'gender'); ?>
  </div>

  <div class="row">
    <?php echo $form->labelEx($model,'email'); ?>
    <?php echo $form->textField($model,'email',array('size'=>45,'maxlength'=>45)); ?>
    <?php echo $form->error($model,'email'); ?>
  </div>

  <div class="row">
    <?php echo $form->labelEx($model,'contact_no'); ?>
    <?php echo $form->textField($model,'contact_no',array('size'=>45,'maxlength'=>45)); ?>
    <?php echo $form->error($model,'contact_no'); ?>
  </div>

  <div class="row">
    <?php echo $form->labelEx($model,'address'); ?>
    <?php echo $form->textField($model,'address',array('size'=>60,'maxlength'=>120)); ?>
    <?php echo $form->error($model,'address'); ?>
  </div>

  <div class="row">
    <?php echo $form->labelEx($model,'state'); ?>
    <?php echo $form->textField($model,'state',array('size'=>45,'maxlength'=>45)); ?>
    <?php echo $form->error($model,'state'); ?>
  </div>

  <div class="row">
    <?php echo $form->labelEx($model,'country'); ?>
    <?php echo $form->textField($model,'country',array('size'=>45,'maxlength'=>45)); ?>
    <?php echo $form->error($model,'country'); ?>
  </div>

  <div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
  </div>

<?php $this->endWidget(); ?>

</div><!-- form -->

I have made the rules for this model is like this

 public function rules()
  {
    // NOTE: you should only define rules for those attributes that
    // will receive user inputs.
    return array(
      array('firstname,lastname,gender,email,contact_no,address,state,country', 'required'),
      array('firstname, lastname', 'length', 'max'=>80),
    );
  }

After all this code I came to see that all the fields are showing validation in a normal way but when going through Ajax Validation the only Firstname, Lastname, Email is showing ajax validation.Rest of the fields are not showing any ajax validation.Can someone tell me where I am doing wrong here?Any help and suggestion will be highly appreciable.
Edited
Here is the code for controller which is handling the Ajax validation

  protected function performAjaxValidation($model)
  {
    if(isset($_POST['ajax']) && $_POST['ajax']==='customers-form')
    {
      echo CActiveForm::validate($model);
      Yii::app()->end();
    }
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:53:50+00:00Added an answer on May 30, 2026 at 4:53 pm

    Just use this in model’s actionCreate()

     public function actionCreate()
      {
        $model=new Customers;
    
        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);
    
        if(isset($_POST['Customers']))
        {
          if(Yii::app()->getRequest()->getIsAjaxRequest())
          {
            echo CActiveForm::validate( array( $model)); 
            Yii::app()->end(); 
          }
          $model->attributes=$_POST['Customers'];
          $valid = $model->validate();
          if($valid)
          {
            $model->save();
            $this->redirect(array('view','id'=>$model->id));
          }
        }
    
        $this->render('create',array(
          'model'=>$model,
        ));
      }
    

    Rest of the files for view will be the same as above made in question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a web form with some fields that you want to validate
I want to create custom form validation in joomla using ajax or jQuery. on-blur
I have a form in a jQuery tab div that is loaded with AJAX:
I have a form that has target=_blank on submit. I want to validate the
I have the following block of code: $(document).ready(function(){ $(#form).submit(function(ev) { ev.preventDefault(); $.ajax({ type: POST,
I have a generic jQuery validation call in a global JS file: $('form').each(function() {
I want to validate, before submitting the form, if the h:selectOneMenu and t:inputFileUpload have
Im using asp.net webforms. c# I want to validate a form. In the codebehind
I want to validate a registration form that accepts an email address in the
I have a form that validates the email address and I want to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.