Radiolist in form

Hi,

I have two types of users, created in my database a user table for email (=username), password and category and two tables where I save the user specific data. I thought about how to do the registration and first thought I could do it with a link like http://example.com/registerA or http://example.com/registerB and then have the value for the category in my form like


 return array(

  'elements'=>array(

    'category'=>array(

          'type'=>'hidden',

          'value'=>'A' or 'B'

        )

      ),

    ),

  ),

  'buttons'=>array(

    'register'=>array(

      'type'=>'submit',

      'label'=>'Register',

    ),

  ),

 );

but since I don’t know how to do the link and then just get A or B from the URL without having to write two different register.php I thought I could let the user do it during registration with a radiolist. That should look like


 return array(

  'elements'=>array(

    'category'=>array(

          'type'=>'radiolist',

          <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />?

        )

      ),

    ),

  ),

  'buttons'=>array(

    'register'=>array(

      'type'=>'submit',

      'label'=>'Register',

    ),

  ),

 );

How do I get the values + labels in this list?

Thx for your help :)

ok, now I tried it with the _form.php, changing a few things and trying to get the radiobuttons via


$form->radioButtonList($model,'category',array('LabelA','LabelB'))

my Problem now is that I do get two radiobuttons named LabelA and LabelB. In my table I have the field category as type enum(‘a’,‘b’). When I select LabelA, nothing is written to my field, when I select LabelB ‘a’ is written to the category field and when I make three radiobuttons(’’,‘LabelA’,‘LabelB’) I get a when choosing LabelA and b when choosing LabelB. But I only want to have two radiobuttons - what is wrong here?

schlydi

Change your items arrays to be an associative type :


array('a'=>'LabelA', 'b'=>'LabelB')

You’re getting this result because the way you have it expands to :


array(0=>'LabelA', 1=>'LabelB')

These then map to enum IDs in the database 1 = a, 2 = b (enums in mysql are really stored by numerical id).