Zen Cart Logo
Forums / General Questions / Easy PHP Question (for someone :( )

Easy PHP Question (for someone :( )

Locked

Views: 2,485

Results 1 to 3 of 3
This thread is locked. New replies are disabled.
26 Apr 2008, 1:41 PM
#1
tracstev avatar

tracstev

New Zenner

Join Date:
Apr 2008
Posts:
61
Plugin Contributions:
0

Easy PHP Question (for someone :( )

Hello

I am trying to insert an extra action on the add to cart button on a product page. I have the javascript i need but i cannot for the life of me add the "onclick" statement to the "input" fuction in tpl_product_info_display.php.

This is the Current HTML output into the browser

<div id="cartAdd">
    <p>Quantity in Cart: 1</p>Add to Cart: <input type="text" name="cart_quantity" value="1" maxlength="6" size="4" /><br /><br /><input type="hidden" name="products_id" value="383" /><input type="image" src="includes/templates/toyshop/buttons/english/button_in_cart.gif" alt="Add to Cart" title=" Add to Cart " />          </div>
  <!--eof Add to Cart Box-->

I would like it to be the following (onclick="javascript:toggleLayer('errorCaution'); return upload_progress();) in bold as shown below.

<div id="cartAdd">
    <p>Quantity in Cart: 1</p>Add to Cart: <input type="text" name="cart_quantity" value="1" maxlength="6" size="4" /><br /><br /><input type="hidden" name="products_id" value="383" /><input type="image" src="includes/templates/toyshop/buttons/english/button_in_cart.gif" alt="Add to Cart" title=" Add to Cart " [B]onclick="javascript:toggleLayer('errorCaution'); return upload_progress();" [/B]/>          </div>
  <!--eof Add to Cart Box-->

This is the current snippet of PHP code in tpl_product_info_display.php:

           <?php
    $display_qty = (($flag_show_product_info_in_cart_qty == 1 and $_SESSION['cart']->in_cart($_GET['products_id'])) ? '<p>' . PRODUCTS_ORDER_QTY_TEXT_IN_CART . $_SESSION['cart']->get_quantity($_GET['products_id']) . '</p>' : '');
            if ($products_qty_box_status == 0 or $products_quantity_order_max== 1) {
              // hide the quantity box and default to 1
              $the_button = '<input type="hidden" name="cart_quantity" value="1" />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT);
            } else {
              // show the quantity box
    $the_button = PRODUCTS_ORDER_QTY_TEXT . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($_GET['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_get_products_quantity_min_units_display((int)$_GET['products_id']) . '<br />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT);
			}
    $display_button = zen_get_buy_now_button($_GET['products_id'], $the_button);
	  ?>
  <?php if ($display_qty != '' or $display_button != '') { ?>
    <div id="cartAdd">
    <?php
      echo $display_qty;
      echo $display_button;
            ?>
          </div>

I know i need to add the "onclick" statement after (BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) but i've been trying all day and im bashing my head against the wall now!.

Please can someone have a look, i'm sure this is straightforward for someone!

Regards

Tracey

26 Apr 2008, 2:58 PM
#2
drbyte avatar

drbyte

Sensei

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

Re: Easy PHP Question (for someone :( )

You might try it in both places, like this:

           <?php
    $display_qty = (($flag_show_product_info_in_cart_qty == 1 and $_SESSION['cart']->in_cart($_GET['products_id'])) ? '<p>' . PRODUCTS_ORDER_QTY_TEXT_IN_CART . $_SESSION['cart']->get_quantity($_GET['products_id']) . '</p>' : '');
            if ($products_qty_box_status == 0 or $products_quantity_order_max== 1) {
              // hide the quantity box and default to 1
              $the_button = '<input type="hidden" name="cart_quantity" value="1" />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT, 'onclick="javascript:toggleLayer(\'errorCaution\'); return upload_progress();"');
            } else {
              // show the quantity box
    $the_button = PRODUCTS_ORDER_QTY_TEXT . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($_GET['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_get_products_quantity_min_units_display((int)$_GET['products_id']) . '<br />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT, 'onclick="javascript:toggleLayer(\'errorCaution\'); return upload_progress();"');
			}
    $display_button = zen_get_buy_now_button($_GET['products_id'], $the_button);
	  ?>
  <?php if ($display_qty != '' or $display_button != '') { ?>
    <div id="cartAdd">
    <?php
      echo $display_qty;
      echo $display_button;
            ?>
          </div>
26 Apr 2008, 3:46 PM
#3
tracstev avatar

tracstev

New Zenner

Join Date:
Apr 2008
Posts:
61
Plugin Contributions:
0

Re: Easy PHP Question (for someone :( )

Thankyou very much,that works a treat!!

All the Best!