开发者

codeigniter set_checkbox problem on an optional input

i have an optional checkbox called checkall

<input name="checkall" type="checkbox" value="ON" <?php echo set_checkbox('checkall', 'ON'); ?> />

i'm sure that the form is submitting that

if i give it a validation rule 开发者_高级运维$this->form_validation->set_rules('checkall', 'Checkall', 'required');it works, but without a rule nothing worked out !

did i miss something? i think form helper doesn't require that for this function to work right ?


I think you're talking about the value being persisted without validation rules. This is STILL a problem in CI 2.x if I recall correctly, and jbreitwiser's patch from January 2010 is still necessary:

http://codeigniter.com/forums/viewthread/96617/P15/#689642

If this is still a problem in CI 2.x it is completely absurd, and I totally agree. But that patch will solve your problem.


If I understand you correctly your checkbox is not submitting with the form? If that is the case, I had a fun time with this question on this thread HERE

PHP wants you to check to see if a checkbox is set or not by verifying whether or not there is a corresponding element in the POST array. If the checkbox was checked, there will be an element of the same name in the POST array (that element will have a NULL value), if the checkbox was NOT checked, then there will be NO matching element in the POST array.

The code would look something like this:

Your input element remains the same --

<input name="checkall" type="checkbox" value="ON" <?php echo set_checkbox('checkall', 'ON'); ?> />

Postback Handler Page gets a new way to validate a checkbox --

if(isset($_POST["checkall"])
{
   $checkall = TRUE;
}
else
{
   $checkall = FALSE;
}

Hopefully I helped, its late and your question is sparse on details.

Regards

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜