Radio Button List Validator Issue


In a form I’ve added radio buttons using radioButtonList. Radio buttons are populated and field is required in model rules.

When I selects one radio and submits form it shows error message for field.

See code here:



echo "<li>" . $form->radioButtonList($model, $attr, $subscription_options_data, array(

        	//'uncheckValue' => null,

        	'separator' => "</li>\n<li>",

        	'container' => '',

        	'template' => "{input} <p class='fnt-size14 font-opensansbd linHnml txt666'><span class='fnt-size14 txt000'><span class='font-rupee'>`</span>{label}</span>{{ DETAILS }}</p>",

            	//'empty' => 0,

    	)) . "</li>\n";



You may see here live: http://www.peoplemat…n/new/subscribe


No one is interested to help me!


probably problem lies in your model.

post your model and controller to let ppl help you. Just posting the view alone is not a good way to get help.

Rules defined as in model class:

public function rules() {

	return array(



    	array('subscription', 'required', 'message' => 'Please choose the subscription above that’s best for you.'),

     	array('subscription', 'in', 'range' =>  array_keys(self::getSubscriptionOptions()), 'message' =>  'Subscription value({value}) is invalid.'),



    	array('firstname, lastname, addr_1, addr_2, city, country, state, postal_code, email, phone', 'required'),

    	array('firstname, lastname, addr_1, addr_2, city', 'length', 'min' => 4, 'max' => 32),


    	array('postal_code', 'length', 'min' => 3, 'max' => 9),

    	array('country', 'exists', 'class' => 'Country', 'attribute' => 'country_id', 'allowEmpty' => FALSE),


     	array('email', 'email', 'checkMX' => TRUE, 'checkPort' => TRUE,  'message' => 'Invalid email or could be a fake {attribute}.'),

     	array('email', 'unique', 'allowEmpty' => FALSE, 'attributeName'  => 'member_email', 'className' => 'User', 'message' => 'Using  "{value}" your are already subscribed with us. Please renew your  subscription.'),



    	array('method, card_no, name_on_card, card_expiry_month, card_expiry_year, card_security_code_cvv', 'required'),

    	array('card_no', 'numerical', 'integerOnly' => true),

    	array('method', 'in', 'range' => array_keys(self::getPaymentMethods())),

    	array('card_security_code_cvv', 'length', 'min' => 3, 'max' => 4),

    	array('card_expiry_month', 'in', 'range' => array_keys(self::getCardExpiryMonths())),

    	array('card_expiry_year', 'in', 'range' => array_keys(self::getCardExpiryYears())),


    	array('netbank', 'required'),




    	array('nlsubscribe', 'boolean'),



Find model class file here:

Which field from model ,you are used for radio button list…?

Like this, in form

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

        <?php echo $form->radioButtonList($model,'menuType',array('1'=>'Page','2'=>'PHP Page', '3'=>'External')); ?>

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

In model rules add the field as required.

public function rules()

  return array(

   array('menuType', 'required'),



In your case put "subscription" as field name.


echo "<li>" . $form->radioButtonList($model, 'subscription', $subscription_options_data, array(

                //'uncheckValue' => null,

                'separator' => "</li>\n<li>",

                'container' => '',

                'template' => "{input} <p class='fnt-size14 font-opensansbd linHnml txt666'><span class='fnt-size14 txt000'><span class='font-rupee'>`</span>{label}</span>{{ DETAILS }}</p>",

                //'empty' => 0,

        )) . "</li>\n";


[size=2]I already added "subscription" as field name:[/size]

Download my model file and check: SubscriptionModel.php

In model its fine.

But in form where u specify "subscription" field is radio button list…?

Post your form.


Probably you’d better check $_POST in your controller, whether $_POST[‘SubscriptionModel’] contains the attribute ‘subscription’ or not. I mean, somehow the form seems to fail to submit it.

I’m not sure, but the following event handler might be the cause of the problem:

Would you please comment it out and see what will happen?


Hmm, I was wrong …

Actually the problem is with radioButtonList container. It works only with “container=‘span’”.

Try your self by creating any radioButtonList and set it’s container=’’. Then this will not validate. Event this will not validate if you pass any tag except only “span”.

You are right.

I’m sorry I was not aware that it is the problem solely in the client side.

I see this code in jquery.yiiactiveform.js:

	var getAFValue = function (o) {

		var type,

			c = [];

		if (!o.length) {

			return undefined;


		if (o[0].tagName.toLowerCase() === 'span') {

			o.find(':checked').each(function () {



			return c.join(',');


		type = o.attr('type');

		if (type === 'checkbox' || type === 'radio') {

			return o.filter(':checked').val();

		} else {

			return o.val();



In your case, “o[0].tagName.toLowerCase()” is ‘div’, not ‘span’.

So it fails to get the proper value of radio button list.


Meanwhile I’ve fixed issue using another trick.

Thanks for your support.

I see. The trick was a hidden field for the attribute … Nice job.