CHtml::activeCheckBox() seems to post '1' when checked, but an empty string ('') when unchecked. I want a single checkbox for a bunch of attributes (such as `email_publicly_visible`) which have boolean values. When the checkbox is unchecked, I get a mysql error because it can't store null into the column.
Should CHtml::activeCheckBox() actually post '0' when unchecked? Is that a bug?
Should an argument be added to it that defines what the value is when unchecked?
Page 1 of 1
CHtml::activeCheckBox
#2
Posted 15 January 2009 - 06:36 AM
Yes, I think adding an option to specify unchecked value is good. Could you create a ticket for that? Thanks!
#3
Posted 15 January 2009 - 06:57 PM
Another question: What's the best way to validate checkboxes?
May I suggest to add another type to CTypeValidator that is "boolean"?
May I suggest to add another type to CTypeValidator that is "boolean"?
#4
Posted 15 January 2009 - 07:02 PM
Not sure if this is needed. There are several ways to validate a boolean (e.g. CRangeValidator, CNumberValidator). I prefer to using CRangeValidator.
#5
Posted 15 January 2009 - 07:53 PM
Ok. Yes, it is definitely not needed, but I think it would be less typing. And I don't see why the type validator should not support it anyways, it is a ''data type" after all.
I'll use the range validator however..
I'll use the range validator however..
#6
Posted 11 May 2009 - 01:58 PM
I want to validate checkBox to know user accept terms and conditions. But the validation is not works.
I did like this:
In model
in views:
How to validate this checBox?
I did like this:
In model
public function rules()
{
return array(
array('terms', 'required'),
array('terms', 'length', 'min'=>1,
'message'=>'You must accept to continue....'),
);
}
in views:
<?php echo CHtml::activeLabelEx($confirm,'terms'); ?>
<?php echo CHtml::activeCheckBox($confirm,'terms'); ?>
<?php echo CHtml::error($confirm,'terms'); ?>
How to validate this checBox?
#7
Posted 11 May 2009 - 11:14 PM
Sorry, it should be like this:
public function rules()
{
return array(
array('terms', 'required'),
array('terms', 'CRangeValidator', 'range'=>array(1),
'message'=>'You must accept to continue....'),
);
}
Share this topic:
Page 1 of 1

Help
This topic is locked











