Validate check box

Hi!

I want to validate a check box but it doesn’t works for me. I tried to use compare, required and boolean validators. Which validator must be used and how?

This check box will be the ‘Agree the Terms and Conditions’. The message when isn’t ticked must be ‘You must agree the Terms and Conditions’.

[color="#006400"]/* Moved to proper forum */[/color]

Hi,

This works for me:





// form

<?php echo $form->checkBox($signup, 'accept');?>


// model rules

array('accept', 'compare', 'compareValue' => 1, 'message' => 'You should accept term to use our service'),



Not sure that is best way. I think ‘require’ validator should work too


array('accept', 'required', 'requiredValue' => 1, 'message' => 'You should accept term to use our service')

"required" validator has "requiredValue" attribute, use it.

Hey can you tell same thing for multiple checkbox validation for any one checkbox is checked

Check This Link ! It Might Help You

http://www.yiiframework.com/wiki/134/enforcing-you-must-agree-requirements-in-forms/

I have Solved this problem by reload captcha after errors.

Here is my code:

Js function in custom.js file:




function reloadCaptcha() {

        jQuery.ajax({

            url: "registration/captcha/refresh/1",

            dataType: "json",

            cache: false,

            success: function(data) {

                jQuery("#yw0").attr("src", data["url"]);

                jQuery("body").data("captcha.hash", [data["hash1"], data["hash2"]]);

            }

        });

    }


//Captcha image which will auto generate 


<img id="yw0" alt="" src="">




//ajaxLink or ajaxSubmitButton


 echo CHtml::ajaxLink('Submit', 'registration', array(

                                    'type' => 'POST',

                                    'success' => 'js:function(data){

                                         var responce = jQuery.parseJSON(data);

                                        if (responce.success) {

                                         locarion.reload();

                                        }else{

                                         reloadCaptcha(data);

                                        }

                                       

                                }',

                                        ), array(

                                    'id' => 'send-link-' . time(),

                                   

                                        )

                                );