This is a discussion on File diff from OSC advanced_search.php within the osCMax v2 Customization/Mods forums, part of the osCMax v2.0 Forums category; Hi, I am customizing and installing Product Extra Fields, and so far it was working fine, but I needed and ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| Hi, I am customizing and installing Product Extra Fields, and so far it was working fine, but I needed and additional feature not included in the package so I started to browse the code and modify it, then I realize something was missing from the installation, and when I added I start to get this error : 'Parse error: syntax error, unexpected T_ELSE in /home/... line 55' When I read the instructions I found a discrepancy between OSCMax and the code, which is understandable, as some lines that used to be in advanced_search.php in OScMAx are instead in advanced_search_result.php. Particularly this portion(Please read my comments added to the original code): //This section validates user input in the form to make sure fields are not empty the contrib instructs to search for it in advanced_search but this code is slightly modified and present in advanced_search_result.php if ( ((keywords == '') || (keywords.length < 1)) && ((dfrom == '') || (dfrom == '<?php echo DOB_FORMAT_STRING; ?>') || (dfrom.length < 1)) && ((dto == '') || (dto == '<?php echo DOB_FORMAT_STRING; ?>') || (dto.length < 1)) && ((pfrom == '') || (pfrom.length < 1)) && ((pto == '') || (pto.length < 1)) ) { error_message = error_message + "* <?php echo ERROR_AT_LEAST_ONE_INPUT; ?>\n"; //This is what is not in OscMax code error_field = document.advanced_search.keywords; error_found = true; } and CHANGE them to read as follows://These changes are in the contrib installation text because of BTS there are already in php This is completely useless in oscMax code because it uses a different way to validate those fields <?php // START: Extra Fields Contribution Search Fields 1.0 foreach ($pef_fields as $field) { echo ' var pef_'.$field['products_extra_fields_id'].' = document.advanced_search.pef_'.$field['products_extra_fields_id'].".value;\n";// Some javascript call? } ?> // This is slightly different in oscMax as the user input validation uses a different if if ( ((keywords == '') || (keywords.length < 1)) && ((dfrom == '') || (dfrom == '<?php echo DOB_FORMAT_STRING; ?>') || (dfrom.length < 1)) && ((dto == '') || (dto == '<?php echo DOB_FORMAT_STRING; ?>') || (dto.length < 1)) && ((pfrom == '') || (pfrom.length < 1)) && ((pto == '') || (pto.length < 1)) <?php //Here is where my problem starts, as this foreach statement inside the IF, is causing the syntax error >> My knowledge of php is limited so I don't understand why is not working // START: Product Extra Fields Contribution Search Fields 1.0 foreach ($pef_fields as $field) { $fieldid = 'pef_'.$field['products_extra_fields_id']; echo " && (( $fieldid == '' ) || ($fieldid.length < 1))"; } // END: Extra Fields Contribution ?> ok here is my modified code ... >>> Please note I validated additional fields and has a slight modification from the oscMax original before adding this missing code. $error = false; //I inserted these lines and then commented out after realizing it wasn't working // START: Extra Fields Contribution Search Fields 1.0 /*foreach ($pef_fields as $field) { echo ' var pef_'.$field['products_extra_fields_id'].' = document.advanced_search.pef_'.$field['products_extra_fields_id'].".value;\n"; }*/ //end comments //My modified IF with additional ANDs added in order to validate some of my fields if ( (isset($HTTP_GET_VARS['keywords']) && empty($HTTP_GET_VARS['keywords'])) && (isset($HTTP_GET_VARS['dfrom']) && (empty($HTTP_GET_VARS['dfrom']) || ($HTTP_GET_VARS['dfrom'] == DOB_FORMAT_STRING))) && (isset($HTTP_GET_VARS['dto']) && (empty($HTTP_GET_VARS['dto']) || ($HTTP_GET_VARS['dto'] == DOB_FORMAT_STRING))) && // $afrom, $hfrom, $ato and $hto added to the code (isset($HTTP_GET_VARS['afrom']) && !is_numeric($HTTP_GET_VARS['afrom'])) && (isset($HTTP_GET_VARS['ato']) && !is_numeric($HTTP_GET_VARS['ato'])) && (isset($HTTP_GET_VARS['hfrom']) && !is_numeric($HTTP_GET_VARS['hfrom'])) && (isset($HTTP_GET_VARS['hto']) && !is_numeric($HTTP_GET_VARS['hto'])) && //end additions (isset($HTTP_GET_VARS['pfrom']) && !is_numeric($HTTP_GET_VARS['pfrom'])) && (isset($HTTP_GET_VARS['pto']) && !is_numeric($HTTP_GET_VARS['pto'])) ) // Here is where the issues started. After I added those lines to the FOreach statement... My problem was I needed to display some of the fields as a Select type field but if I don't validate them then the system returned the error 'empty field ...' // START: Product Extra Fields Contribution Search Fields 1.0 foreach ($pef_fields as $field) { $fieldid = 'pef_'.$field['products_extra_fields_id']; echo " && (( $fieldid == '' ) || ($fieldid.length < 1))"; } // END: Extra Fields Contribution Any ideas? |
| Sponsored Links | ||
| ||
|
#2
| |||
| |||
| broken if-then-else at Parse error: syntax error, unexpected T_ELSE in /home/... line 55 so whatever that file is, it's either 1) missing a ";" somewhere directly above the if-then-else 2) missing a ";" somewhere in the if-then-else 3) has improperly opne and/or close braces {}
__________________ so endith the lesson<think>sometimes I just sit's and thinks</think> "Here you are with a hand full of holes, a thumb up your ass, and a big grin to pass the time of day with." - TWB |
|
#3
| |||
| |||
| Thanks for replying in fact it was a missing } After much searching I found out there was also a validating function inside advanced_search.js.php Now I want to validate a select, because the current validation from the contribution, but I don't know which function it must be used or if have to create a new one. The only function that seems to check the form is >>> <?php // START: Extra Fields Contribution Search Fields 1.0 $pef_fields = array(); $pef_fields_query = tep_db_query("SELECT products_extra_fields_id, products_extra_fields_name FROM " . TABLE_PRODUCTS_EXTRA_FIELDS . " WHERE (languages_id = 0 OR languages_id = " . (int)$languages_id . ") AND products_extra_fields_status ORDER BY products_extra_fields_order"); while ($field = tep_db_fetch_array($pef_fields_query)) { $pef_fields[] = $field; } // END: Extra Fields Contribution ?> function check_form() { var error_message = "<?php echo JS_ERROR; ?>"; var error_found = false; var error_field; var keywords = document.advanced_search.keywords.value; var dfrom = document.advanced_search.dfrom.value; var dto = document.advanced_search.dto.value; //Start Age and Height Variables mod added var afrom = document.advanced_search.afrom.value; var ato = document.advanced_search.ato.value; var afrom_float; var ato_float; //height var hfrom = document.advanced_search.hfrom.value; var hto = document.advanced_search.hto.value; var hfrom_float; var hto_float; //End var pfrom = document.advanced_search.pfrom.value; var pto = document.advanced_search.pto.value; var pfrom_float; var pto_float; <!-- /*if ( ((keywords == '') || (keywords.length < 1)) && ((dfrom == '') || (dfrom == '<?php //echo DOB_FORMAT_STRING; ?>') || (dfrom.length < 1)) && ((dto == '') || (dto == '<?php //echo DOB_FORMAT_STRING; ?>') || (dto.length < 1)) && ((pfrom == '') || (pfrom.length < 1)) && ((pto == '') || (pto.length < 1)) )*/ --> <?php // START: Extra Fields Contribution Search Fields 1.0 foreach ($pef_fields as $field) { echo ' var pef_'.$field['products_extra_fields_id'].' = document.advanced_search.pef_'.$field['products_extra_fields_id'].".value;\n"; } ?> if ( ((keywords == '') || (keywords.length < 1)) && ((dfrom == '') || (dfrom == '<?php echo DOB_FORMAT_STRING; ?>') || (dfrom.length < 1)) && ((dto == '') || (dto == '<?php echo DOB_FORMAT_STRING; ?>') || (dto.length < 1)) && ((pfrom == '') || (pfrom.length < 1)) && ((pto == '') || (pto.length < 1)) <?php // START: Product Extra Fields Contribution Search Fields 1.0 foreach ($pef_fields as $field) { $fieldid = 'pef_'.$field['products_extra_fields_id']; echo " && (( $fieldid == '' ) || ($fieldid.length < 1))"; } // END: Extra Fields Contribution ?> ) { error_message = error_message + "* <?php echo ERROR_AT_LEAST_ONE_INPUT; ?>\n"; error_field = document.advanced_search.keywords; error_found = true; } This function is completely unaware of my Select type field, if I select anything from a select it always return an error 'Error At least one of the fields in the search form must be entered.', so it's validating my Select as an empty field, instead .. Here is the portion of the code where the SELECTS are within the Advanced Search form: <!--New fields Inserted here in query--> <tr> <td class="fieldKey"><?php echo ENTRY_HAIR; ?></td> <td class="fieldValue"><?php echo tep_draw_pull_down_menu('products_to_products_extr a_fields_id', tep_get_extra(array(array('id' => '', 'text' => TEXT_ALL_HAIR)))); ?></td> </tr> <tr> <td class="fieldKey"><?php echo ENTRY_EYES; ?></td> <td class="fieldValue"><?php echo tep_draw_pull_down_menu('products_to_products_extr a_fields_id', tep_get_extra1(array(array('id' => '', 'text' => TEXT_ALL_EYES)))); ?></td> </tr> <tr> <!--End new fields--> Both are class="fieldValue" so I assumed they will be validated but that is not happening, the only difference from the default code is I used the function tep_draw_pull_down_menu(), because I wanted them to be a SELECT type, instead of INPUT field. |
|
#4
| |||
| |||
| I don't understand why the values of my select end up empty http://.../advanced_search_result.ph...description=1& categories_id=&inc_subcat=1&manufacturers_id=1& products_to_products_extra_fields_id=&products_to_ products_extra_fields_id=& afrom=&ato=&hfrom=&hto=&dfrom=16%2F02%2F2000&dto=0 9%2F07%2F2008 I have a SELECT pulldown menu in my advanced search form >>> <tr> <td class="fieldKey"><?php echo ENTRY_HAIR; ?></td> <td class="fieldValue"><?php echo tep_draw_pull_down_menu('products_to_products_extr a_fields_id', tep_get_hair(array(array('id' => '', 'text' => TEXT_ALL_HAIR)))); ?></td> </tr> <tr> <td class="fieldKey"><?php echo ENTRY_EYES; ?></td> <td class="fieldValue"><?php echo tep_draw_pull_down_menu('products_to_products_extr a_fields_id', tep_get_eyes(array(array('id' => '', 'text' => TEXT_ALL_EYES)))); ?></td> </tr> The pull down shows fine all values, for instance Hair has the options: Please Select >>> Blond >>> Brunette If either one is selected the SELECT type behaves like is the option is Please SELECT as you can see above. My function 'tep_get_hair' added to general_output.php under includes/functions/ function tep_get_hair($hair_array = '') { if (!is_array($hair_array)) $hair_array = array(); $hair_query = tep_db_query("select products_extra_fields_value from " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " where products_extra_fields_id = '1'"); while ($hair = tep_db_fetch_array($hair_query)) { $hair_array[] = array('id' => $hair['products_extra_fields_id'], 'text' => $hair['products_extra_fields_value']); } return $hair_array; } Browses the table and selects the values where the products extra fields id is 1, which is the id for the extra field Hair. When I check at the source of the browser's output in the advanced search form I noticed>>> td class="fieldKey">Hair:</td> <td class="fieldValue"><select name="products_to_products_extra_fields_id"><optio n value="" selected="selected">Please Select</option><option value="" selected="selected">Blond</option><option value="" selected="selected">Brunette</option></select></td> </tr> <tr> <td class="fieldKey">Eyes:</td> <td class="fieldValue"><select name="products_to_products_extra_fields_id"><optio n value="" selected="selected">Please Select</option><option value="" selected="selected">Green</option><option value="" selected="selected">Hazel</option></select></td> I noticed all option values are EMPTY! is this because of the way I retrieve these values from my table? Should I create another table and refer to it instead? All extra fields are validated in .js and php ... so why I don't get any values from those selects? |
|
#5
| |||
| |||
| <?php $select_str = "select distinct " . $select_column_list . " m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, NULL as specials_new_products_price, NULL as final_price "; $from_str = "from (" . TABLE_PRODUCTS . " p left join " . TABLE_PRODUCTS_TO_PRODUCTS_EXTRA_FIELDS . " p2pef on p.products_id=p2pef.products_id) left join " . TABLE_MANUFACTURERS . " m on m.manufacturers_id=p.manufacturers_id, " . TABLE_PRODUCTS_DESCRIPTION . " pd left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id, " . TABLE_CATEGORIES . " c, " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c"; $where_str .= "(pd.products_name like '%" . tep_db_input($keyword) . "%' or p.products_model like '%" . tep_db_input($keyword) . "%' or m.manufacturers_name like '%" . tep_db_input($keyword) . "%' or p2pef.products_extra_fields_value like '%" . tep_db_input($keyword) . "%'"; ?> // create column list $define_list = array('PRODUCT_LIST_MODEL' => PRODUCT_LIST_MODEL, 'PRODUCT_LIST_NAME' => PRODUCT_LIST_NAME, 'PRODUCT_LIST_MANUFACTURER' => PRODUCT_LIST_MANUFACTURER, 'PRODUCT_LIST_HAIR' => PRODUCT_LIST_HAIR, 'PRODUCT_LIST_EYES' => PRODUCT_LIST_EYES, 'PRODUCT_LIST_PRICE' => PRODUCT_LIST_PRICE, 'PRODUCT_LIST_QUANTITY' => PRODUCT_LIST_QUANTITY, 'PRODUCT_LIST_WEIGHT' => PRODUCT_LIST_WEIGHT, 'PRODUCT_LIST_IMAGE' => PRODUCT_LIST_IMAGE, 'PRODUCT_LIST_BUY_NOW' => PRODUCT_LIST_BUY_NOW); asort($define_list); $column_list = array(); reset($define_list); while (list($key, $value) = each($define_list)) { if ($value > 0) $column_list[] = $key; } // BOF Separate Pricing Per Customer if(!tep_session_is_registered('sppc_customer_group _id')) { $customer_group_id = '0'; } else { $customer_group_id = $sppc_customer_group_id; } // EOF Separate Pricing Per Customer $select_column_list = ''; for ($i=0, $n=sizeof($column_list); $i<$n; $i++) { switch ($column_list[$i]) { case 'PRODUCT_LIST_MODEL': $select_column_list .= 'p.products_model, '; break; case 'PRODUCT_LIST_MANUFACTURER': $select_column_list .= 'm.manufacturers_name, '; break; case 'PRODUCT_LIST_HAIR': $select_column_list .= 'ph.hair, '; break; case 'PRODUCT_LIST_EYES': $select_column_list .= 'pe.eyes, '; break; case 'PRODUCT_LIST_QUANTITY': $select_column_list .= 'p.products_quantity, '; break; case 'PRODUCT_LIST_IMAGE': $select_column_list .= 'p.products_image, '; break; case 'PRODUCT_LIST_WEIGHT': $select_column_list .= 'p.products_weight, '; break; } } I am trying to read the values from a Select, the values are passed but unfortunately there is something on this query that is not taking them on the search ... Please let me know what i can do, I added 2 tables with these structures: Table products_hair Field Type Collation Attributes Null Default Extra Action options_id int(11) No auto_increment Browse distinct values Change Drop Primary Unique Index Fulltext hair varchar(64) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext products_extra_fields_type_id int(11) No Browse distinct values Change Drop Primary Unique Index Fulltext products_id int(3) No 0 the other table is: Field Type Collation Attributes Null Default Extra Action options_id int(11) No auto_increment Browse distinct values Change Drop Primary Unique Index Fulltext eyes varchar(64) latin1_swedish_ci No Browse distinct values Change Drop Primary Unique Index Fulltext products_extra_fields_type_id int(11) No Browse distinct values Change Drop Primary Unique Index Fulltext products_id int(3) No 0 Browse distinct values Change Drop Primary Unique Index Fulltext I am having a hard time trying to figure out what the query does, and I will appreciate if someone can 'clean' it for me, I need to check my added tables and I am not sure how. |
|
#6
| |||
| |||
| I modified the form in order to allow more extra fields as Select, but I can't find a way to modify it in order to allow my extra fields Selects to be selected as like %Option from select% >>> example Hair---> Blond, ..., so the query will read Select ... like %blond% select distinct p.products_image, p.products_weight, m.manufacturers_name, m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from (products p left join products_to_products_extra_fields p2pef on p.products_id=p2pef.products_id) left join manufacturers m ON p.manufacturers_id = m.manufacturers_id left join specials s on p.products_id = s.products_id, products_description pd, categories c, products_to_categories p2c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '3' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p.products_date_added >= '20000320' and p.products_date_added <= '20080907' order by pd.products_name This second query is the result of writing in the input field, and I need to fix the above query in order to display tep_db_input($keyword) from the select, BTW is there something like tep_db_select($option) function, somewhere, or similar? select distinct p.products_image, p.products_weight, m.manufacturers_name, m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from (products p left join products_to_products_extra_fields p2pef on p.products_id=p2pef.products_id) left join manufacturers m ON p.manufacturers_id = m.manufacturers_id left join specials s on p.products_id = s.products_id, products_description pd, categories c, products_to_categories p2c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '3' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and ((pd.products_name like '%rubia%' or p.products_model like '%rubia%' or m.manufacturers_name like '%rubia%' or p2pef.products_extra_fields_value like '%rubia%' or pd.products_description like '%rubia%') ) order by pd.products_name |
|
#7
| ||||
| ||||
| How about adding some [ c o d e ] tags to your code, so people might actually bother reading your posts? |
|
#8
| |||
| |||
| I added comments all over the place, and divide it in sections: I am trying to figure out how can I use tep_pull_down_menu(...), to display a pulldown, that can then be passed to the MySQL Query! So far I found out the difference between the results given by using keywords and the way I want to input the info is the way keywords are entered into a variable and fetched and compared from an array, but my pull down menus although it uses a function to fetch the array and retrieve the values, that is not working, 1. It succeeds displaying the pulldown but as they are not keyboards but they are options I thought I could use something similar to the manufacturers pulldown, which does work, and use p2pef >>> products_to_products_extra_fields but is not working at all. The problem is the way the table is laid out: Your new fields values appear in the same column so I couldn't figure out what kind of query I had to do in order to fetch these values from my table, as they are in different rows, so I am open to ideas. For instance PHP Code: Last edited by icecold; 07-13-2008 at 04:36 PM. |
|
#9
| |||
| |||
| I modified the form in order to allow more extra fields as Select, but I can't find a way to modify it in order to allow my extra fields Selects to be selected as like %Option from select% >>> example Hair---> Blond, ..., so the query will read Select ... like %blond% Code: select distinct p.products_image, p.products_weight, m.manufacturers_name, m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from (products p left join products_to_products_extra_fields p2pef on p.products_id=p2pef.products_id) left join manufacturers m ON p.manufacturers_id = m.manufacturers_id left join specials s on p.products_id = s.products_id, products_description pd, categories c, products_to_categories p2c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '3' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and p.products_date_added >= '20000320' and p.products_date_added <= '20080907' order by pd.products_name Code: select distinct p.products_image, p.products_weight, m.manufacturers_name, m.manufacturers_id, p.products_id, pd.products_name, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from (products p left join products_to_products_extra_fields p2pef on p.products_id=p2pef.products_id) left join manufacturers m ON p.manufacturers_id = m.manufacturers_id left join specials s on p.products_id = s.products_id, products_description pd, categories c, products_to_categories p2c where p.products_status = '1' and p.products_id = pd.products_id and pd.language_id = '3' and p.products_id = p2c.products_id and p2c.categories_id = c.categories_id and ((pd.products_name like '%rubia%' or p.products_model like '%rubia%' or m.manufacturers_name like '%rubia%' or p2pef.products_extra_fields_value like '%rubia%' or pd.products_description like '%rubia%') ) order by pd.products_name[/quote] |
|
#10
| ||||
| ||||
| Now that gets easier to read, you could edit your previous posts to add the [ c o d e ] tags on them too. They are divided in sections? Sure. Easily readable? At least not to me. |
| Sponsored Links | ||
| ||
| |
| Thread Tools | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| No access to php.ini file! | crystina | osCMax v2 Installation issues | 3 | 04-05-2007 08:25 PM |
| file diff software | chrismole | Off topic & Chit Chat | 4 | 01-15-2007 09:58 PM |
| Hello i need help with my english.php file | reysent | osCommerce 2.2 Modification Help | 6 | 02-20-2005 09:28 AM |
| Error on checkout_process.php file ...please help ??? | nrwalker | osCommerce 2.2 Modification Help | 1 | 06-28-2004 06:19 PM |
| check_ip.php missing file? | AtroxAngel | osCommerce 2.2 Installation Help | 1 | 01-24-2003 07:04 AM |