daipayan Posted October 4, 2013 Posted October 4, 2013 Hello, I am new to PHP as well as Oscommerce. I have the following problem in product_info.php Here I want to validate the product attribute selection before submitting to Shopping Cart. I had inserted the validation in template_top.php i.e. <script language="javascript"><!-- function validate(cart_quantity) { <?php $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "' order by popt.products_options_name"); while ($products_options_name = tep_db_fetch_array($products_options_name_query)) { ?> if (cart_quantity.elements['id[<?php echo (int)$products_options_name['products_options_id']; ?>]'].value == -999) { alert('Sie müssen die Optionen für Ihr Produkt wählen: <?php echo $products_options_name['products_options_name']; ?>'); cart_quantity.elements['id[<?php echo (int)$products_options_name['products_options_id']; ?>]'].focus(); return false; } <?php } ?> } //--></script> Now, to validate this above code, I need to insert 'onsubmit="return validate(this);"' in echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); of product_info.php page, but failed to do that. Please help me. Link for my website is http://shop.christian-grig.de/product_info.php/day-acuvue-p-67 Hope to hear from you all soon. Regards, Daipayan
Chris H Posted October 6, 2013 Posted October 6, 2013 This tester <?php require('includes/application_top.php'); ?> <script> function validate(){ alert("Daipayan's javascript"); } </script> <?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product'), 'post', 'onsubmit="validate()"'); ?> <button>Submit</button> </form> works all right for me from my public_html/catalog though it doesn't return anything, just displays an alert.
daipayan Posted October 22, 2013 Author Posted October 22, 2013 Hello there, I am using version 2.3 where I am unable to input the code as you said so, need something to insert the small piece of code by somehow! I want to display the alert only, need nothing else. This tester <?php require('includes/application_top.php'); ?> <script> function validate(){ alert("Daipayan's javascript"); } </script> <?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product'), 'post', 'onsubmit="validate()"'); ?> <button>Submit</button> </form> works all right for me from my public_html/catalog though it doesn't return anything, just displays an alert.
Jack_mcs Posted October 22, 2013 Posted October 22, 2013 There is. most likely, an addon that already does this so you should check that before reinventing the wheel. For example, if you want to make it so your customers have to pick an attribute, there is the must select addon. Or if you are concerned about the quantity available of the attributes, there is the QTPro addon. Support Links: For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc. All of My Addons Get the latest versions of my addons Recommended SEO Addons
Recommended Posts
Archived
This topic is now archived and is closed to further replies.