Creating a Block - Can't get $form->checkbox to work
Permalink 1 user found helpful
In creating a Block, I found that it would be beneficial to have True/False data represented as a checkbox. I've added a field in the database of type "I1" to capture 0 or 1 data to represent the checkbox. In my setup, I'm not using anything like a "form_setup_html.php" such as in the autonav or other standard Concrete blocks. Is this something that I would need to do in order to use a checkbox in my add/edit form?
I am having problems with getting the checkbox to update the database when submitting the add/edit form. I've looked at the API, but don't understand what I need to do in order for this to work. Which items mean what, and how do they relate?
(I don't particularly consider myself a noob, but sure feel like one at the moment :-)) Any help would be appreciated, and thanks in advance!
I am having problems with getting the checkbox to update the database when submitting the add/edit form. I've looked at the API, but don't understand what I need to do in order for this to work. Which items mean what, and how do they relate?
(I don't particularly consider myself a noob, but sure feel like one at the moment :-)) Any help would be appreciated, and thanks in advance!
I wrote a manual a week or two back. It's added as attachment, just in case. What I think is the problem. You haven't loaded the helper yet like this
A 30 second look at the document you provided gave me precisely what I was missing. Many thanks Maynar!
If anybody else is running into issues with the syntax of the form helper for any of the functions, this is definitely a good resource!
Maynar - Where did you find this?
If anybody else is running into issues with the syntax of the form helper for any of the functions, this is definitely a good resource!
Maynar - Where did you find this?
bpysher, could you please share your insight. I can't get the db to update with the checkbox value either. I have the db field defined just like in the autonav. I just don't understand why it works and mine doesn't.
-Steve
-Steve
This manual is great thanks
Justin
Justin
echo $form->hidden('key','0');
echo $form->checkbox('key','1',$key);
echo $form->checkbox('key','1',$key);
yamanoi, if a hidden field is required, then how does the checkbox in autonav block work? It doesn't appear to use any hidden field. I'm confused as to the proper approach to implementing checkboxes. Any help appreciated. Thanks.
-Steve
-Steve
Ok, I finally figured this out. The magic occurs in the block controller's "save" method. That's where the db value corresponding to the checkbox state is set. That's necessary because a checkbox's value is not submitted with the form if the checkbox isn't checked. So you don't need a hidden field; you just need to implement a "save" method in your block controller. See the autonav block for an example. Oi! It took me too long to figure this out! :-/
-Steve
-Steve