Forums / General Questions / How do I create 148 checkboxes in the product entry page?

How do I create 148 checkboxes in the product entry page?

Views: 879

Results 1 to 8 of 8
25 May 2011, 5:20 PM
#1
rj42 avatar

rj42

New Zenner

Join Date:
May 2011
Posts:
5
Plugin Contributions:
0

How do I create 148 checkboxes in the product entry page?

Zen Cart v1.3.9h

I have manually edited the database to add 148 fields in table "products", all of which can have values of "0" or "1." Some products will have them all 0, some products will have only one of them be 1, some products will have a few be 1, and very few products will have them be all 1.

If I edit /admin/includes/modules/product/collect_info.php to have:

          <tr>
            <td class="main">Y1W01 *TEST*</td>
            <td class="main"><?php echo zen_draw_separator('pixel_trans.gif', '24', '15') . ' ' . zen_draw_input_field('products_Y1W01', $pInfo->products_Y1W01, zen_set_field_length(TABLE_PRODUCTS, 'products_Y1W01')); ?></td>
          </tr>
          <tr>
            <td colspan="2"><hr></td>
          </tr>

and have added p.products_Y1W01 as one of the fields in the select at the top of the page

and have edited update_product.php to include

                            'products_Y1W01' => zen_db_prepare_input($_POST['products_Y1W01']),

in the $sql_data_array,

I am given a text box that can be edited with a one-digit number. Changing this updates the database (I checked with a separate php script to make sure it actually IS changing).

However, instead of a text box that will read "0" or "1," I would like to have it be a checkbox that can be ticked.

I've spent the last two days trying to understand the syntax of a checkbox and I'm just not getting it.

Can anyone help explain what I need to do?

25 May 2011, 5:56 PM
#2
rj42 avatar

rj42

New Zenner

Join Date:
May 2011
Posts:
5
Plugin Contributions:
0

Re: How do I create 148 checkboxes in the product entry page?

It looks like my subject line was changed. My question isn't how to make 148 checkboxes ... it's how to make ONE checkbox. If I can make one checkbox, I can make 148. I just don't understand the syntax for checkboxes.

26 May 2011, 6:38 AM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: How do I create 148 checkboxes in the product entry page?

There are lots of examples in the existing Zen Cart code:

Read this: https://www.zen-cart.com/tutorials/index.php?article=39 and then use that info to search the admin files for: zen_draw_checkbox_field

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

26 May 2011, 2:25 PM
#4
rj42 avatar

rj42

New Zenner

Join Date:
May 2011
Posts:
5
Plugin Contributions:
0

Re: How do I create 148 checkboxes in the product entry page?

I guess I'm just looking for an explanation of the syntax ... what do the parameters mean?

Something like

('fieldname', 'yesvalue', 'novalue', ... )

Is there such a document, other than guessing my way through examples in the DTK?

26 May 2011, 2:59 PM
#5
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: How do I create 148 checkboxes in the product entry page?

Did you already take a look at the function? (zen_draw_checkbox_field)

Of course you can look it up in the files you have, but the Zen Cart code also appears to be published (using phpxref) here:
http://www.zen-cart.com/docs/xref-1-3-8/nav.html?index.html

8tiny.com/source/zencart/nav.html?includes/functions/html_output.php.source.html#l414

26 May 2011, 3:21 PM
#6
rj42 avatar

rj42

New Zenner

Join Date:
May 2011
Posts:
5
Plugin Contributions:
0

Re: How do I create 148 checkboxes in the product entry page?

Hi, paulm!

I see the function is

function zen_draw_checkbox_field($name, $value = '', $checked = false, $compare = '', $parameters = '')

but I'm lost as how to set the $value to what's in the database. I can do it with a textfield, but the syntax of the checkbox has me lost.

I'm doing variations on a theme of

zen_draw_checkbox_field('products_Y1W01', '1', (($products->fields['products_Y1W01'] == '1') ? true : false), 'id="products_Y1W01"');

but I'm still missing something.

26 May 2011, 4:00 PM
#7
rj42 avatar

rj42

New Zenner

Join Date:
May 2011
Posts:
5
Plugin Contributions:
0

Re: How do I create 148 checkboxes in the product entry page?

Here's the new line. It will change from 1 to 0, but not from 0 to 1. (I have to manually change the value to get it to 1.)

zen_draw_checkbox_field('products_Y1W01', (($pInfo->products_Y1W01 == '1') ? true : false), (($pInfo->products_Y1W01 == '1') ? true : false), 'id="products_Y1W01"'); ?>

For the second parameter, I've also tried $pInfo->products-Y1W01 and that seemed to do the same thing.

26 May 2011, 4:23 PM
#8
paulm avatar

paulm

Totally Zenned

Join Date:
Nov 2003
Posts:
1,878
Plugin Contributions:
5

Re: How do I create 148 checkboxes in the product entry page?

It's been a long time since I played with textfields and checkboxes, but as far as I remember the general idea is the same.

A catch may be that an unchecked checkfield returns no value.