Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Creating required fields


blasto

Recommended Posts

I need to make some extra fields I have added to the product listing required fields. The fields have been created using "Product Attributes Product Type" contribution (I have already posted there but the thread has been very quiet.

 

Here's the problem: I am adding text fields which customers need to fill in before adding the product (in this case an event booking) to the cart. The fields names are generated by a php script and its left me stumped at making them required fields. Here's the code in question:

 

      // BOF Option Type Feature
     //$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)) {

     $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name, popt.products_options_type, popt.products_options_length, popt.products_options_comment 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)) {
			//clr 030714 add case statement to check option type
       switch ($products_options_name['products_options_type']) {
         case PRODUCTS_OPTIONS_TYPE_TEXT:
           //CLR 030714 Add logic for text option
           $products_attribs_query = tep_db_query("select distinct patrib.options_values_price, patrib.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = '" . $products_options_name['products_options_id'] . "'");
           $products_attribs_array = tep_db_fetch_array($products_attribs_query);
           $tmp_html = '<input type="text" name ="id[' . TEXT_PREFIX . $products_options_name['products_options_id'] . ']" size="' . $products_options_name['products_options_length'] .'" maxlength="' . $products_options_name['products_options_length'] . '" value="' . $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] .'">  ' . $products_options_name['products_options_comment'] ;
           if ($products_attribs_array['options_values_price'] != '0') {
             $tmp_html .= '(' . $products_attribs_array['price_prefix'] . $currencies->display_price($products_attribs_array['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .')';
            	}
?>
          <tr>
             <td class="main"colspan="2"><?php echo $products_options_name['products_options_name'] . ':'; ?></td></tr>
             <tr>
             <td class="main" colspan="2"><?php echo $tmp_html;  ?></td>
           </tr>

 

Looking at the source code on my browser, the field names appear as:

 
            <td class="main"colspan="2">1. Name:</td></tr>
             <tr>
             <td class="main" colspan="2"><input type="text" name ="id[txt_2]" size="60" maxlength="60" value="">  </td>
           </tr>
           <tr>
             <td class="main"colspan="2">2. Organisation:</td></tr>
             <tr>
             <td class="main" colspan="2"><input type="text" name ="id[txt_6]" size="60" maxlength="60" value="">  </td>
           </tr>

 

Obviously, the field names will vary from product to product although always have the same "id[txt_*]" format. My php and java knowledge is "work in progress" and any help would be much appreciated.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...