KanimozhiPalanisamy
KanimozhiPalanisamy

Reputation: 63

Yii $form->radioButtonList - CSS to align horizontally

I created a form that contain radio button for credit and debit.

I want to display these two in a single. For that I use this command:

<?php echo $form>radioButtonList(
         $model, 
         'description',
         array('credit'=>'Credit', 'debit'=>'Debit'),
         array(
            'labelOptions'=>array('style'=>'display:inline'),
            'separator'=>'  ')
         ); ?>

Now it works, but I want to store it in database if I give submit it shows an error:

Undefined index description.

I dont know how to clear that. I want to add this: array('name'=>'description')

<div class="row">
    <?php echo $form->labelEx($model,'Description'); ?>
    <?php echo $form->radioButtonList(
     $model,
     'description',
     array('credit'=>'Credit','debit'=>'Debit'),
     array(
        'labelOptions'=>array('style'=>'display:inline'),
        'separator'=>'  ')); ?>
    <?php echo $form->error($model,'description'); ?>
</div>

Upvotes: 0

Views: 2251

Answers (2)

C&#233;sar Quintero
C&#233;sar Quintero

Reputation: 21

You can use,

$form->field($model, 'description')->inline()->radioList(['C' => 'Credit', 'D' => 'Debit']);

See: yii\bootstrap\ActiveField

Upvotes: 2

KanimozhiPalanisamy
KanimozhiPalanisamy

Reputation: 63

Finally i found the mistake and clear it..i change my code like this and it works..

<div class="row">
		<?php echo $form->labelEx($model,'Description'); ?>
		<?php echo $form->radioButtonList($model, 'description',
                    array(  'C' => 'Credit',
                            'D' => 'Debit'),array(
    'labelOptions'=>array('style'=>'display:inline'), // add this code
    'separator'=>'  ','name'=>'description'
) );?>
		<?php echo $form->error($model,'description'); ?>
        </div>

Upvotes: 1

Related Questions