Radio Button Validation Problem

I have three radio buttons in my view, but for some reason they always fail the "required" validation.

Here are the rules in my model





   public $plan;

    public $business_name;

    public $first_name;

    public $last_name;

    public $website;

    public $phone_number;

    public $email;

    public $re_email;

    public $street_address;

    public $city;

    public $state;

    public $zip_code;

    public $sub_domain;

    public $terms;




    public function rules()

    {

 

        return array(

            // username and password are required

            array('plan,phone_number,business_name,first_name,last_name,email,sub_domain,re_email,street_address,city,state,zip_code', 'required'),

            array('terms', 'required', 'message'=>'You must agree to the Terms and Conditions to continue.'),

            // check email format

            array('email', 'email'),

            // email needs to be authenticated

            array('email', 'authenticate_email'),

            // subdomain needs to be authenticated

            array('sub_domain', 'authenticate_subdomain'),

            // phone needs to be authenticated

            array('phone_number', 'authenticate_phone'),

            // email and re_email must be identical

            array('re_email', 'compare', 'compareAttribute'=>'email', 'operator'=>'==', 'message'=>'The email addresses you entered do not match.'),

        );

    }



Here is the controller code for the form




    public function actionStartNow()

    {

        $model=new StartForm;


        // check to see if a plan value was passed

        if (isset($_GET['plan']))

        {

            if ($_GET['plan']==1 || $_GET['plan']==2 || $_GET['plan']==3)

            {

                $model->plan=$_GET['plan'];

            }

        }


        // if it is ajax validation request

        if(isset($_POST['ajax']) && $_POST['ajax']==='start-form')

        {

            echo CActiveForm::validate($model);

            Yii::app()->end();

        }

        if(isset($_POST['StartForm']))

        {

            $model->attributes=$_POST['StartForm'];

            if ($model->validate()) {

                $model->startNewAccount();

                $this->render('started', array('model'=>$model));

            } else {

                $this->render('start', array('model'=>$model));

            }

        } else {

            $this->render('start', array('model'=>$model));

        }

    }



And here is my view




<div class="container">

    <div class="row-fluid margin-bottom-10">

        <?php

        $form=$this->beginWidget('CActiveForm', array(

            'id'=>'start-form',

            'enableAjaxValidation'=>true,

            'enableClientValidation'=>true,

            'clientOptions'=>array(

                'validateOnSubmit'=>true,

                'afterValidate' => 'js:function(form, data, hasError) { 

                    if(hasError) {

                        for(var i in data) {

                            $("#"+i).addClass("error_input");

                        }

                        $("#error_div").show();

                        $(window).scrollTop($("#error_div").position());

                        return false;

                    }

                    else {

                        form.children().removeClass("error_input");

                        $("#error_div").hide();

                        return true;

                    }

                }',

                'afterValidateAttribute' => 'js:function(form, attribute, data, hasError) {

                    if(hasError) 

                    {

                        $("#"+attribute.id).addClass("error_input");

                    } else {

                        $("#"+attribute.id).removeClass("error_input");

                    }

                }'

            ),

            'htmlOptions'=>array(

                'class'=>'reg-page',

            ),

        )); ?>

            <h3>Start Now</h3>

            <div id="error_div">

            <?php

                echo $form->errorSummary($model);

            ?>

            </div>

            <legend>Choose a Plan</legend>

            <div class="controls">

                <div>

                    <label class="radio inline"><?php echo $form->radioButton($model, 'plan', array('value'=>1, 'uncheckValue'=>null)); ?> <span style="font-weight:800; color: #666666;">Free Plan</span> - it's free</label>

                    <br />

<label class="radio inline"><?php echo $form->radioButton($model, 'plan', array('value'=>2, 'uncheckValue'=>null)); ?> <span style="font-weight:800; color: #666666;">Plan 4</span></label>

                    <br />

                    <label class="radio inline"><?php echo $form->radioButton($model, 'plan', array('value'=>3, 'uncheckValue'=>null)); ?> <span style="font-weight:800; color: #666666;">Plan 3</span></label>

                </div>

            </div>

            <legend>About Your Business</legend>

            <div class="controls">

                <div>

                    <?php echo $form->labelEx($model,'business_name'); ?>

                    <?php echo $form->textField($model,'business_name', array('class'=>'span12 tool-tipper', 'data-original-title'=>'Business Name', 'data-content'=>'This name will appear throughout your application and be visible to your employees.')); ?>

                </div>

            </div>

            <div class="controls">

                <div>

                    <?php echo $form->labelEx($model,'street_address'); ?>

                    <?php echo $form->textField($model,'street_address', array('class'=>'span12')); ?>

                </div>

            </div>

            <div class="controls">

                <div>

                    <?php echo $form->labelEx($model,'city'); ?>

                    <?php echo $form->textField($model,'city', array('class'=>'span12')); ?>

                </div>

            </div>

            <div class="controls">

                <div class="span7">

                    <?php echo $form->labelEx($model,'state'); ?>

                    <?php //echo $form->textField($model,'state', array('class'=>'span12')); ?>

                    <?php echo $form->dropDownList($model, 'state', $model->populateSelectStates(), array('empty' => '(Select a state)')); ?>

                </div>

                <div class="span1">


                </div>

                <div class="span4">

                    <?php echo $form->labelEx($model,'zip_code'); ?>

                    <?php echo $form->textField($model,'zip_code', array('class'=>'span12')); ?>

                </div>

            </div>

            <div class="controls">

                <div>

                    <?php echo $form->labelEx($model,'website'); ?>

                    <?php echo $form->textField($model,'website', array('class'=>'span12')); ?>

                </div>

            </div>

            <div class="controls">

                <div>

                    <?php echo $form->labelEx($model,'phone_number'); ?>

                    <?php echo $form->textField($model,'phone_number', array('class'=>'span12')); ?>

                </div>

            </div>

            <legend>User Info</legend>

            <div class="controls">

                <div class="span6">

                    <?php echo $form->labelEx($model,'first_name'); ?>

                    <?php echo $form->textField($model,'first_name', array('class'=>'span12')); ?>

                </div>

                <div class="span6">

                    <?php echo $form->labelEx($model,'last_name'); ?>

                    <?php echo $form->textField($model,'last_name', array('class'=>'span12')); ?>

                </div>

            </div>

            <div class="controls">

                <div>

                    <?php echo $form->labelEx($model,'email'); ?>

                    <?php echo $form->textField($model,'email',array('class'=>'span12 tool-tipper', 'data-original-title'=>'Email Address', 'data-content'=>'This will be your email address that you will use to login to your  application.  We will send your password to this email address.')); ?>

                </div>

            </div>

            <div class="controls">

                <div>

                    <?php echo $form->labelEx($model,'re_email'); ?>

                    <?php echo $form->textField($model,'re_email',array('class'=>'span12 tool-tipper', 'data-original-title'=>'Re-Enter Email Address', 'data-content'=>'Please re-enter your email address.  We just want to make sure its right.')); ?>

                </div>

            </div>

            <legend>Choose Your Subdomain</legend>

            <div class="controls">

                <div>

                    <?php echo $form->labelEx($model,'sub_domain'); ?>

                    <?php echo $form->textField($model,'sub_domain', array('class'=>'tool-tipper span6', 'placeholder'=>'your-school', 'data-content'=>'This will be the url where you and your students will go to access your online school.')); ?>.kikflo.com

                </div>

            </div>

            <div>

                <div class="span1 inline">

                    <?php echo $form->checkBox($model,'terms', array('class'=>'inline')); ?>

                </div>

                <div class="span11 inline">

                    <?php echo $form->labelEx($model,'terms', array('class'=>'inline')); ?>

                </div>

            </div>

            <div>

                <?php echo CHtml::submitButton('Continue', array('class'=>'btn-u pull-right')); ?>

            </div>

            <?php $form->error($model,'business_name'); ?>

            <?php $form->error($model,'street_address'); ?>

            <?php $form->error($model,'city'); ?>

            <?php $form->error($model,'state'); ?>

            <?php $form->error($model,'zip_code'); ?>

            <?php $form->error($model,'website'); ?>

            <?php $form->error($model,'first_name'); ?>

            <?php $form->error($model,'last_name'); ?>

            <?php $form->error($model,'email'); ?>

            <?php $form->error($model,'phone_number'); ?>

            <?php $form->error($model,'re_email'); ?>

            <?php $form->error($model,'sub_domain'); ?>

            <?php $form->error($model,'terms'); ?>

            <?php $form->error($model,'plan'); ?>

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

    </div><!--/row-fluid-->

</div><!--/container-->     

<!--=== End Content Part ===-->



My work has grinded to a halt. Can somebody show me the way - btw everything else validates fine except for the radio buttons

any suggestions, I’m still stuck

Hi,

you can try this…


array('plan', 'required', 'requiredValue' => 1, 'message' => 'Please Select the radio button.'),

not sure it’s work or not…