Jump to content

alizarin

Members
  • Content count

    4
  • Joined

  • Last visited

Everything posted by alizarin

  1. alizarin

    Imprint Text Options

    I needed added fields to be required and here was my quick solution - Basically for every product add-to-cart page I put in a js validation function that defaults to just submitting okay. But for each added field from this contrib a check is done to see if it's empty and if it is you're given a warning and the form doesn't submit. Could be done cleaner but it works and thought I'd share. Starting with oscommerce-2.2ms2 I have other contribs on this page but I don't think the code is affected below except line numbers. All in catalog/product_info.php Somewhere around line 51 change -----------CHANGE -------------------------------------------- <!-- body_text //--> <td width="100%" valign="top"><?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product')); ?><table border="0" width="100%" cellspacing="0" cellpadding="0"> -----------TO------------------------------------------------------- <!-- body_text //--> <?php $strFormFunctionParams="onsubmit='return validateForm(this);'"?> <td width="100%" valign="top"><?php echo tep_draw_form('cart_quantity', tep_href_link(FILENAME_PRODUCT_INFO, tep_get_all_get_params(array('action')) . 'action=add_product'),"post",$strFormFunctionParams); ?><table border="0" width="100%" cellspacing="0" cellpadding="0"> ------------------------------------------------------------------------------------------------------------------------------------ Somewhere around line 184 -----------CHANGE -------------------------------------------- <!-- denuz products text attributes --> <?php $text_attributes_query = tep_db_query("select pta.*, cbta.products_text_attributes_text from products_text_attributes as pta, products_text_attributes_enabled as ptae, customers_basket_text_attributes as cbta where ptae.products_text_attributes_id = pta.products_text_attributes_id and ptae.products_id = " . tep_get_prid($HTTP_GET_VARS['products_id']) . " and cbta.products_text_attributes_id = pta.products_text_attributes_id and cbta.session_id = '" . tep_session_id() . "'"); if (tep_db_num_rows($text_attributes_query) == 0) $text_attributes_query = tep_db_query("select pta.* from products_text_attributes as pta, products_text_attributes_enabled as ptae where ptae.products_text_attributes_id = pta.products_text_attributes_id and ptae.products_id = " . tep_get_prid($HTTP_GET_VARS['products_id'])); while ($text_attributes = tep_db_fetch_array($text_attributes_query)) { ?> <table border="0" cellspacing="0" cellpadding="2"><tr> <td> <?php echo $text_attributes['products_text_attributes_name'] . ': </td><td>' . tep_draw_input_field('products_text_attributes_' . $text_attributes['products_text_attributes_id'], tep_not_null($text_attributes['products_text_attributes_text']) ? $text_attributes['products_text_attributes_text'] : ''); ?> </td> </tr></table> <?php } ?> <!-- eof denuz products text attributes --> -----------TO------------------------------------------------------- <!-- denuz products text attributes --> <?php $strAttribsJS=""; // 2011-04-20 AMT change - Required extra field ?> <?php $text_attributes_query = tep_db_query("select pta.*, cbta.products_text_attributes_text from products_text_attributes as pta, products_text_attributes_enabled as ptae, customers_basket_text_attributes as cbta where ptae.products_text_attributes_id = pta.products_text_attributes_id and ptae.products_id = " . tep_get_prid($HTTP_GET_VARS['products_id']) . " and cbta.products_text_attributes_id = pta.products_text_attributes_id and cbta.session_id = '" . tep_session_id() . "'"); if (tep_db_num_rows($text_attributes_query) == 0) { $text_attributes_query = tep_db_query("select pta.* from products_text_attributes as pta, products_text_attributes_enabled as ptae where ptae.products_text_attributes_id = pta.products_text_attributes_id and ptae.products_id = " . tep_get_prid($HTTP_GET_VARS['products_id'])); $strAttribsJS=""; // 2011-04-20 AMT change - Required extra field } while ($text_attributes = tep_db_fetch_array($text_attributes_query)) { ?> <?php $strAttribsJS.=" if(tf.products_text_attributes_".$text_attributes['products_text_attributes_id'].".value=='') {alert('Field \'".$text_attributes['products_text_attributes_name']."\' required'); return false;} "; // 2011-04-20 AMT change - Required extra field ?> <table border="0" cellspacing="0" cellpadding="2"><tr> <td> <?php echo $text_attributes['products_text_attributes_name'] . ': </td><td>' . tep_draw_input_field('products_text_attributes_' . $text_attributes['products_text_attributes_id'], tep_not_null($text_attributes['products_text_attributes_text']) ? $text_attributes['products_text_attributes_text'] : ''); ?> </td> </tr></table> <?php } ?> <?php // BOF 2011-04-20 AMT change - Required extra field ?> <script language="javascript"> function validateForm(tf){ <?php print $strAttribsJS ?> return true; } </script> <?php // EOF 2011-04-20 AMT change - Required extra field ?> -----------END CHANGES--------------------------------------------------------------------------------------------------------------
×