Yii Framework Forum: Form Validation With Ajaxsubmitbutton - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Form Validation With Ajaxsubmitbutton Showing validation errors of the form when using ajaxSubmitButton Rate Topic: ***** 3 Votes

#21 User is offline   bvpk 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 19-June 13

Posted 24 October 2013 - 05:55 AM

View Postbennouna, on 02 November 2012 - 05:15 AM, said:

My bad you're totally right. In an ajax webapp, I returned a string or the json errors, so it was slightly different.



do this like

var obj = $.parseJSON(data);
//alert(obj.registerUser_username);
$.each(obj, function(key, val) {
//alert(key);
$("#"+key+"_em_").text(val);
$("#"+key+"_em_").show();
//alert(data);
});
then display errors on your modal
0

#22 User is offline   bharry 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 20-August 13

Posted 24 March 2014 - 05:30 AM

Thanks for the code
0

#23 User is offline   Mayank Singhai 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 29-May 12

Posted 10 June 2014 - 08:22 AM

Works like a charm. Thank you. :)

View Postseenivasan, on 16 March 2013 - 06:07 AM, said:

Dear Friend

First I should appreciate you for sharing a very useful tip.

Regarding your apprehensions, I need to clarify with you on certain aspects of my code.

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'user-form',
        'enableAjaxValidation'=>true,
        'clientOptions'=>array(
            'validateOnSubmit'=>true,
            'afterValidate'=>'js:function(form,data,hasError){
                        if(!hasError){
                                $.ajax({
                                        "type":"POST",
                                        "url":"'.CHtml::normalizeUrl(array("test/eleven")).'",
                                        "data":form.serialize(),
                                        "success":function(data){$("#test").html(data);},
                                        
                                        });
                                }
                        }'
        ),
)); ?>



1.
'validateOnSubmit'=>true,

The above ensures that the form will not be submitted even there is a single error.

2.
 if(!hasError)

The above also ensures that the form will not be submitted by ajax enen there is single error.

Till the submission is error free, form will display errors.

Regards.

0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users