Forums / Customization from the Admin / zen_draw_checkbox_field - how do I get my custom field to show selection in checkbox?

zen_draw_checkbox_field - how do I get my custom field to show selection in checkbox?

Started by johnlewisdesign on 18 Apr 2012, 12:49 AM · Views: 1,707

Results 1 to 3 of 3
18 Apr 2012, 12:49 AM
#1
johnlewisdesign avatar

johnlewisdesign

New Zenner

Join Date:
Jan 2012
Location:
South West UK
Posts:
17
Plugin Contributions:
0

zen_draw_checkbox_field - how do I get my custom field to show selection in checkbox?

Hi guys

I recently added some new fields to my admin product info page. I have four fields - two of them are checkboxes. All are working fine. I can view them frontend too, and have customised it exactly how I need it, thanks to this awesome forum and its generous users, documenting their work. :yes:

I can get the checkbox values to apply to the database, but when revisiting the product, the checkbox state is not observed. eg the box is no longer checked (value 0) even though the db states value 1. Not good.

I suppose I need to store the checkbox state as a new variable and use it, but how? Here's my code for one checkbox, which is a yes/no 1/0 answer.

<tr>
<td class="main"><?php echo 'Organic '; ?></td>
<td class="main"><?php echo zen_draw_checkbox_field('products_organic', '1', (($pinfo->fields['products_organic'] == '1') ? true : false), 'id="products_organic"') . "Organic"; ?><br /></td>
</tr>

Trial and error got me this far - I'm soooo close to completion its paining me! Anyone?

Thanks guys.

30 Apr 2012, 11:16 PM
#2
johnlewisdesign avatar

johnlewisdesign

New Zenner

Join Date:
Jan 2012
Location:
South West UK
Posts:
17
Plugin Contributions:
0

Re: zen_draw_checkbox_field - how do I get my custom field to show selection in checkbox?

Bump - can nobody show me how to retrieve the checkbox status from the DB and mark accordingly?

1 May 2012, 2:12 PM
#3
jc8125 avatar

jc8125

Zen Follower

Join Date:
Oct 2007
Posts:
143
Plugin Contributions:
0

Re: zen_draw_checkbox_field - how do I get my custom field to show selection in checkbox?

johnlewisdesign:

Bump - can nobody show me how to retrieve the checkbox status from the DB and mark accordingly?

what happens if you change to this: (not an expert by any means, but my custom fields and all other fields on page use $pinfo->xxxxx instead of $pinfo->fields['xxxxx']

<tr>
<td class="main"><?php echo 'Organic '; ?></td>
<td class="main"><?php echo zen_draw_checkbox_field('products_organic', '1', (($pinfo->products_organic == '1') ? true : false), 'id="products_organic"') . "Organic"; ?><br /></td>
</tr>