2

Yii framework, yii-user extension (using latest version of both, to date): how do I add a simple "checkbox" field for the profile of all users?

I am logged in as admin, and went to user/profileField/admin. I can add new field but the closest I get to is adding a "BOOL" field which is rendered as a dropdown, while I need a checkbox... . When "BOOL" is used I cannot specify the widget and even if I could, there's no documentation on those yii-user widgets.

Any help is welcome!

bool.dev
  • 17,508
  • 5
  • 69
  • 93
Boaz Rymland
  • 1,459
  • 11
  • 29
  • damn, i'm very close to giving up on this extension/module and implementing myself. actually, i doubt it any help here would change my mind. – Boaz Rymland Apr 16 '12 at 18:29
  • Have you asked in the forum they're usually quite good. – Paystey Apr 18 '12 at 14:54
  • From my experience the forum is sometimes not that effective (but it depends, mostly on luck I guess). Yet, this place (stackoverflow) is, probably due to its interesting social incentives, at least as good as the forum. Thanks for the advice though! – Boaz Rymland Apr 18 '12 at 18:16

2 Answers2

3

Open up modules/yii-user/views/user/registration.php. Around line 40, add something like this:

else if ($field->field_type=='BINARY') echo $form->checkBox($profile,$field->varname,array());

Now when you want to create a checkbox field, choose the BINARY field type. If you want to require that it's checked, add this to the 'Other Validator' field: {"compare":{"compareValue":"1"}}

paulsz
  • 31
  • 2
1

I've had a look around the docs for that extension and I don't actually see a single checkbox anywhere in the screen shots or mentioned anywhere in the wiki either.

You might be able to dive in and add support for one in the places you need it, Yii nicely handles all the HTML elements so it shouldn't be too hard to add the feature in a primitive form. CHtml::checkBox() or CHtml::checkBoxList().

Then again if your already running into problems with it, it's probably going to be easier in the long run for you to write what you need yourself.

Paystey
  • 3,287
  • 2
  • 18
  • 32
  • Yes, your last sentence is already what I'm doing. And as usual in Yii, its fast to develop so I'm happy with this direction. – Boaz Rymland Apr 20 '12 at 05:05