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

  • SEARCH
  • Home
  • 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 7833591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:47:13+00:00 2026-06-02T12:47:13+00:00

I use Yii client validation to validate some inputs and when there is an

  • 0

I use Yii client validation to validate some inputs and when there is an error in the user input, Yii client Validation does not prevent submit and does not prevent ajax request.
I use grid widget “carvw-grid” and when user click submit button its make ajax request to update “carvw-grid” content with results. I want to prevent submit and ajax request when there is a client validation error.

here is my script code:

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.myloading').show();
$('.myshow').hide();
$('.myresult').slideUp().delay(3000).queue(function() {
    $(this).show();
    $('.myloading').hide();
    $('.myloading').addClass('myshow');
    });
    });

$('.search-form form').submit(function(){
    $.fn.yiiGridView.update('carvw-grid', {
        data: $(this).serialize()
    });
    return false;
});
");

and here is my form

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'carvw-form',
    'action'=>Yii::app()->createUrl($this->route),
    'method'=>'get',
    'enableAjaxValidation'=>false,
    'enableClientValidation'=>true,
    'focus'=>array($model,'OWNER_ID'),
    'clientOptions' => array('validateOnSubmit'=>true, 'validateOnType'=>true),

)); ?>

and here is my submit button

<div class="row buttons">
    <?php echo CHtml::submitButton('search',array('class'=>'search-button')); ?>
</div>

and here is my grid

<?php 
    $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'carvw-grid',
    'dataProvider'=>$model->search(),

    'columns'=>array('CAR_COMPANY_NAME','MODEL_YEAR',
        'CAR_COLOR_NAME',
        'USING_TYPE_NAME',array(
            'class'=>'CButtonColumn',
        ),
    ),
));

 ?>

How can i prevent submit and ajax request on client validation errors?

  • 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-06-02T12:47:15+00:00Added an answer on June 2, 2026 at 12:47 pm

    Maybe you need to use afterValidate function instead of binding submit event. Into CActiveForm.clientOptions array add following element:

    'afterValidate' => 'js:afterValidate',
    

    In your javascript file:

    function afterValidate(form, data, hasError) {
        if (!hasError) {    
            $.fn.yiiGridView.update('carvw-grid', {
                data: $(this).serialize()
            });
        }
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use yii::app()->user->id in a form and to save the username in
I'm prety new to yii framework so i could use some help with something.
in Yii framework, can I use unique validation rule to check uniqueness of an
I'm building a web application and eventually would want to use Yii framework. But
I am confused as to how to use CSort in Yii for a drag
I use subversion to manage my yii website (php framework) and have separate backend
Use case: user clicks the link on a webpage - boom! load of files
Use case: I've just entered insert mode, and typed some text. Now I want
Use Case When a user goes to my website, they will be confronted with
I'm use Yii PHP framework but i cant write this code, what's the true

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.