[Closed] set_checkbox dosn't work with Form Helper |
[eluser]adamp1[/eluser]
Is it just me or do nearly all the following not work with the form helper functions. set_checkbox set_select set_radio None of these can easily be used with the form_dropdown, form_checkbox or form_radio functions since they return a string. The only way to get them to work is by using the 4th parameter and passing in additional data. Since seems a bit odd to me. Why have to parts of the framework which don't work together unless you use a not very pretty work around. For example, setting a checkbox value. This won't work since set_checkbox returns a string rather than a TRUE false VALUE. Code: print form_checkbox('my_checkbox','1', set_checkbox('my_checkbox', '1', TRUE));
[eluser]slowgary[/eluser]
It needs to return a string since it'll be setting " checked='checked'", or am I missing something? That said, there used to be a bug in those 3 functions that renders the 3rd parameter useless unless you've also loaded the form validation library, and judging by a post that just popped up in the forums, that's still the case. http://ellislab.com/forums/viewthread/104294
[eluser]adamp1[/eluser]
No my point is that it does return a string, the form_checkbox method requires a boolean value to say whether it should be checked or not.
[eluser]slowgary[/eluser]
Ahh... I see. But that seems redundant... why even call set_checkbox()? Why not just test the $_POST val of the checkbox and pass true or false to form_checkbox? I guess it seems like you'd only use one or the other. Also... set_checkbox returns either " checked='checked'" or "", which I *think* evaluates to TRUE or FALSE respectively, no?
[eluser]adamp1[/eluser]
The reason being you can't pass in a default value by just checking if the $_POST value is set. You are right with what the return value evaluates to. I tried that a few days ago and it didn't work, but now it does. Well this case seems to be solved then, thanks for going over it.
[eluser]PeterGreffen[/eluser]
I gave up on the set_checkbox and returned to: Code: <input name='my_checkbox' value='1' <?php echo (isset($_POST['my_checkbox']) ? 'CHECKED' : '');?> |
Welcome Guest, Not a member yet? Register Sign In |