ScottShipley Posted June 2, 2008 Posted June 2, 2008 Hi, I'm trying to adapt a search contribution (Simple Search Box) so that it only searches within the current category but i can't figure out how to get the category id into the form. This is the code before i touch it <script> function clearDefault(el) { if (el.defaultValue==el.value) el.value = "" } </SCRIPT> <form name="quick_find" action="advanced_search_result.php" method="get"> <table width="1" border="0" vertical-align: bottom;"> <tr> <td> <div align="right"> <!-- This is the input box where visitors enter keywords etc --> <input type="text" name="keywords" value="Search this category" size="30" ONFOCUS="clearDefault(this)"> <input type="hidden" name="search_in_description" value="1" /> <input type="hidden" name="inc_subcat" value="1" /> </div> </td> <td> <div align="left" style="border: 0px solid #333333;"> <!-- OSC Search Submit Button Below --> <?php //echo tep_image_submit('button_search.gif', BOX_HEADING_SEARCH); ?> <!-- Default Gray Search Submit Button Below --> <input type="submit" name="search" value="Search" class="formfield" border="0" width="79" height="25"> </div> </td> </tr> </table> </form> i think what i need to do is put something like this into the form <input type="hidden" name="categories_id" value="category id goes here" /> but i can't figure out how to get the category id as the cPath is in the url, not the category id. Anyone know how i can do this? Thanks Scott
spooks Posted June 2, 2008 Posted June 2, 2008 Did'nt you have this in another thread? <?php echo '<a href="' . tep_href_link(FILENAME_CATEGORIES, 'action_att=delete_product_attribute&attribute_id=' . $attributes_values['products_attributes_id'] . '&attribute_page=' . $attribute_page . '&action=' . $HTTP_GET_VARS['action'] . '&pID=' . $pInfo->products_id . '&cPath=' .$cPath . '&fold=' . $foldout . '#atts', 'NONSSL') , '">' . tep_image_button('button_delete.gif', IMAGE_DELETE); ?></a> Thats one of mine, hope you can work that out. Sam Remember, What you think I ment may not be what I thought I ment when I said it. Contributions: Auto Backup your Database, Easy way Multi Images with Fancy Pop-ups, Easy way Products in columns with multi buy etc etc Disable any Category or Product, Easy way Secure & Improve your account pages et al.
ScottShipley Posted June 2, 2008 Author Posted June 2, 2008 Thanks but i've sorted it now, i should learn to be patient before asking for help! here's the code for anyone that might find it useful <script> function clearDefault(el) { if (el.defaultValue==el.value) el.value = "" } </SCRIPT> <form name="quick_find" action="advanced_search_result.php" method="get"> <table width="1" border="0" vertical-align: bottom;"> <tr> <td> <div align="right"> <!-- This is the input box where visitors enter keywords etc --> <input type="text" name="keywords" value="Search this category" size="30" ONFOCUS="clearDefault(this)"> <input type="hidden" name="search_in_description" value="1" /> <input type="hidden" name="inc_subcat" value="1" /> <input type="hidden" name="categories_id" value="<?php echo $current_category_id; ?>" /> </div> </td> <td> <div align="left" style="border: 0px solid #333333;"> <!-- OSC Search Submit Button Below --> <?php //echo tep_image_submit('button_search.gif', BOX_HEADING_SEARCH); ?> <!-- Default Gray Search Submit Button Below --> <input type="submit" name="search" value="Search" class="formfield" border="0" width="79" height="25"> </div> </td> </tr> </table> </form> i was trying to use $category_id instead of $current_category_id and i wasn't echoing it Scott
ScottShipley Posted June 2, 2008 Author Posted June 2, 2008 also added this line in below the category one for when you're trying to search within products by manufacturer <input type="hidden" name="manufacturers_id" value="<?php echo $manufacturers_id; ?>" /> Hope thats useful to people Scott
spooks Posted June 2, 2008 Posted June 2, 2008 You take care here, your making a v long url, & there is a limit to the size of the $_GET. You could loose the sid too, why not do it in php? Sam Remember, What you think I ment may not be what I thought I ment when I said it. Contributions: Auto Backup your Database, Easy way Multi Images with Fancy Pop-ups, Easy way Products in columns with multi buy etc etc Disable any Category or Product, Easy way Secure & Improve your account pages et al.
ScottShipley Posted June 2, 2008 Author Posted June 2, 2008 its done in pretty much the same way as the advanced search i beleive, and the URL is smaller than the one that produces. Please tell me if i'm wrong Scott
spooks Posted June 2, 2008 Posted June 2, 2008 The character limit for $_GET is 100, excluding data your count is 85 ish, so your user cant even use the 30 chars you've given & you havent limited that even then. If your not using cookies then you'll loose the sid, which you will anyway as you havent used tep_href_link. Be very careful when moving away from the standard methods. Sam Remember, What you think I ment may not be what I thought I ment when I said it. Contributions: Auto Backup your Database, Easy way Multi Images with Fancy Pop-ups, Easy way Products in columns with multi buy etc etc Disable any Category or Product, Easy way Secure & Improve your account pages et al.
ScottShipley Posted June 2, 2008 Author Posted June 2, 2008 so how does the advanced search do it as that adds the information to the url? Scott
spooks Posted June 2, 2008 Posted June 2, 2008 Ok, I`ve done some tests and I must admit I am able to exceed the 100 char limit, it is something in my notes though & theres plenty of stories on the web re truncated url's. It maybe browser dependant. You will notice that for the most part osC uses abreviated terms in the $_GET, like cID for categories pID for product. Sam Remember, What you think I ment may not be what I thought I ment when I said it. Contributions: Auto Backup your Database, Easy way Multi Images with Fancy Pop-ups, Easy way Products in columns with multi buy etc etc Disable any Category or Product, Easy way Secure & Improve your account pages et al.
ScottShipley Posted June 2, 2008 Author Posted June 2, 2008 i'll try it out for a bit and see what happens, its still on a development machine at the moment so its not like its going to be anoying customers if its not working. You're right about the session id though but my sessions dont seem to be working very well at the minute anyway so it might have something to do with that. I'm using sql sessions and they dont seem to hold very long and they break quite easily! Scott
ScottShipley Posted June 15, 2008 Author Posted June 15, 2008 ok i decided to start a fresh with this one and do it using php as Sam suggested as i was loosing the session id. here's the code i've got so far <?php echo tep_draw_form('advanced_search', tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get', 'onSubmit="return check_form(this);"') . tep_hide_session_id(); ?> <table width="1" border="0" cellspacing="0" cellpadding="0"> <tr> <td><?php echo tep_draw_input_field('keywords', '', 'size="10" maxlength="30" style="width: ' . (BOX_WIDTH-30) . 'px"'); $search_in_description = "true"; ?></td> <td><?php echo tep_image_submit('button_search2.gif', IMAGE_BUTTON_SEARCH); ?></td> </tr> </table> now my first problem is that i now have the session id in the URL twice, once before the keywords and again afterwards. my second problem is getting the information i hid using the original method to work as i dont know how to hide the fields in a php form. The way i have attempted to do it is just to assign values to variables as below but only the manufacturers id seems to be passing through to the next page (it does this without the need to assign) $categories_id = $current_category_id; $inc_subcat = "true"; maybe i'm doing something stupid here, i'm not sure but any help would be appreciated. Scott
ScottShipley Posted June 15, 2008 Author Posted June 15, 2008 i've changed a little bit of the code which has removed the 2nd session id which was being displayed and i've also taken out the check form function as i'm not currently using it. The code now looks like this <?php echo tep_draw_form('advanced_search', tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get'); ?> <table width="1" border="0" cellspacing="0" cellpadding="0"> <tr> <td><?php echo tep_draw_input_field('keywords', '', 'size="10" maxlength="30" style="width: ' . (BOX_WIDTH-30) . 'px"'); $search_in_description = "true"; ?></td> <td><?php echo tep_image_submit('button_search2.gif', IMAGE_BUTTON_SEARCH); ?></td> </tr> </table> still have issues with the category id though Scott
ScottShipley Posted June 15, 2008 Author Posted June 15, 2008 and its not searching in description either so it looks like its only passing values that are within the form. Does anyone know how to hide the fields like you would in a html form? Scott
ScottShipley Posted July 1, 2008 Author Posted July 1, 2008 still not figured this one out, can anyone help? Scott
spooks Posted July 1, 2008 Posted July 1, 2008 still not figured this one out, can anyone help? When you say hide I assume you mean form field? tep_draw_hidden_field('search_in_description', '1') ; To enable search in description, use above. Sam Remember, What you think I ment may not be what I thought I ment when I said it. Contributions: Auto Backup your Database, Easy way Multi Images with Fancy Pop-ups, Easy way Products in columns with multi buy etc etc Disable any Category or Product, Easy way Secure & Improve your account pages et al.
ScottShipley Posted July 1, 2008 Author Posted July 1, 2008 When you say hide I assume you mean form field? tep_draw_hidden_field('search_in_description', '1') ; To enable search in description, use above. Thats a great help!! Now using the following code which seems to work fine at the moment, you seem to be able to spot my errors quite easily though so see what you think and let me know if you spot anything which could be a problem. <?php echo tep_draw_form('advanced_search', tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get'); ?> <table width="1" border="0" cellspacing="0" cellpadding="0"> <tr> <td><?php echo tep_draw_input_field('keywords', '', 'size="10" maxlength="30" style="width: ' . (BOX_WIDTH-30) . 'px"'); echo tep_draw_hidden_field('search_in_description', '1'); echo tep_draw_hidden_field('categories_id', $current_category_id); echo tep_draw_hidden_field('inc_subcat', '1'); ?></td> <td><?php echo tep_image_submit('button_search2.gif', IMAGE_BUTTON_SEARCH); ?></td> </tr> </table> Thanks again! Scott
spooks Posted July 1, 2008 Posted July 1, 2008 Thats a great help!! Now using the following code which seems to work fine at the moment, you seem to be able to spot my errors quite easily though so see what you think and let me know if you spot anything which could be a problem. <?php echo tep_draw_form('advanced_search', tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get'); ?> <table width="1" border="0" cellspacing="0" cellpadding="0"> <tr> <td><?php echo tep_draw_input_field('keywords', '', 'size="10" maxlength="30" style="width: ' . (BOX_WIDTH-30) . 'px"'); echo tep_draw_hidden_field('search_in_description', '1'); echo tep_draw_hidden_field('categories_id', $current_category_id); echo tep_draw_hidden_field('inc_subcat', '1'); ?></td> <td><?php echo tep_image_submit('button_search2.gif', IMAGE_BUTTON_SEARCH); ?></td> </tr> </table> Thanks again! Only error I see is you havent closed the form!! Html is fine for that. Sam Remember, What you think I ment may not be what I thought I ment when I said it. Contributions: Auto Backup your Database, Easy way Multi Images with Fancy Pop-ups, Easy way Products in columns with multi buy etc etc Disable any Category or Product, Easy way Secure & Improve your account pages et al.
ScottShipley Posted July 1, 2008 Author Posted July 1, 2008 oops! now added </form> to the bottom, everything appears to be working fine so thanks for your help Scott
ScottShipley Posted July 3, 2008 Author Posted July 3, 2008 ok one last thing on this mod, can someone help me to add a message to the search box (search this category for example) which is removed when you click on the field. I got it to display the message but couldn't get it to disapear. There seems to be a difference between the html form method and the php one. Thanks Scott
Recommended Posts
Archived
This topic is now archived and is closed to further replies.