Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Need help fixing this sidebox search code from 'double submitting' the search.

    Hi gang,

    This file is modified from:
    includes/templates/custom/sideboxes.tpl_search.php

    I'm trying to avoid the customer from double clicking on the sidebox search button and having mysql get clogged with additional searching. (this has been an ongoing issue and driving me crazy)

    I tried to modify the one that occurs on checkout confirmation, but I'm unable to get it to function here. Can anyone find any errors in this code. In the checkout confirmation code, the script language is located in a separate file. I added it to the top of this file instead.

    Any help would be great.
    thanks,
    Jeff Michaels

    PHP Code:
    <?php
    /**
     * Side Box Template
     *
     * @package templateSystem
     * @copyright Copyright 2003-2010 Zen Cart Development Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     * @version $Id: tpl_search.php 15881 2010-04-11 16:32:39Z wilt $
     */
     
    ?>
     <script language="javascript"><!--
     function submitonce()
    {
      var button = document.getElementById("btn_submit");
      button.style.cursor="wait";
      button.disabled = true;
      setTimeout('button_timeout()', 4000);
      return false;
    }
    function button_timeout() {
      var button = document.getElementById("btn_submit");
      button.style.cursor="pointer";
      button.disabled = false;
    }
    //--></script>

    <?php
       $content 
    "";
      
    $content .= '<script language="javascript" type="text/javascript"><!--' "\n";
      
    $content .= ' function popupHelp(url) {' "\n";
      
    $content .= "  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=650,screenX=150,screenY=200,top=150,left=400') \n";
      
    $content .= ' } //--></script>' "\n";
      
    $content .= '  <div class="forward"><a class="legendText" href="javascript:popupHelp(\'' zen_href_link(FILENAME_POPUP_SEARCH_HELP) . '\')">' TEXT_SEARCH_HELP_LINK '</a></div>' "\n";
      
    $content .= '<div id="' str_replace('_''-'$box_id 'Content') . '" class="sideBoxContent centeredContent">';
      
      
    $content .= zen_draw_form('quick_find'zen_href_link(FILENAME_ADVANCED_SEARCH_RESULT''$request_typefalse), 'get');
      
    $content .= zen_draw_hidden_field('main_page',FILENAME_ADVANCED_SEARCH_RESULT);
      
    $content .= zen_draw_hidden_field('search_in_description''0') . zen_hide_session_id();

      if (
    strtolower(IMAGE_USE_CSS_BUTTONS) == 'no') {
        
    $content .= zen_draw_input_field('keyword''''size="18" maxlength="100" style="width: ' . ($column_width-30) . 'px" value="' HEADER_SEARCH_DEFAULT_TEXT '" onfocus="if (this.value == \'' HEADER_SEARCH_DEFAULT_TEXT '\') this.value = \'\';" onblur="if (this.value == \'\') this.value = \'' HEADER_SEARCH_DEFAULT_TEXT '\';"') . '<br /><br />' zen_image_submit (BUTTON_IMAGE_SEARCH,HEADER_SEARCH_BUTTON);
        
    $content .= '<br /><a href="' zen_href_link(FILENAME_ADVANCED_SEARCH) . '">' BOX_SEARCH_ADVANCED_SEARCH '</a>';
      } else {
        
    $content .= zen_draw_input_field('keyword''''size="18" maxlength="100" style="width: ' . ($column_width-30) . 'px" value="' HEADER_SEARCH_DEFAULT_TEXT '" onfocus="if (this.value == \'' HEADER_SEARCH_DEFAULT_TEXT '\') this.value = \'\';" onblur="if (this.value == \'\') this.value = \'' HEADER_SEARCH_DEFAULT_TEXT '\';"') . '<br /><input type="submit" value="' HEADER_SEARCH_BUTTON '" onsubmit="submitonce();"  style="width: 50px" />';
      }
      
    $content .= '<br />';
      
    $content .= CLICK_ONCE;
      
    $content .= '<br /><br />';
      
    $content .= EXACT_SEARCH;
      
    $content .= "</form>";
      
    $content .= '</div>';
    ?>
    Jeff Michaels,
    pres of Musical Creations Ltd.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Need help fixing this sidebox search code from 'double submitting' the search.

    Since you've already got jQuery on the page (albeit a very old version), you can do it like this instead:

    Put the following code into a new file at /includes/templates/YOUR_TEMPLATE_NAME/jscript/jscript_zen_disable_search_on_submit.js

    Code:
    /**
     * this uses the attr() method for compatibility with old jQuery 1.4.2.
     * Changing it to prop() would be smarter, after upgrading to a current version of jQuery
     */
      $(function() {
        $('FORM[name="quick_find"]')
          .submit(function() {
             $(this).find("input[type='submit']").attr("disabled", true);
          })
      });
    And remove the other things you tried, since they relate to button IDs that don't exist on the page.

    An optional variation you could do would be to add a waiting indicator, as follows:
    1. Copy the /your-renamed-admin/images/loadingsmall.gif file to your store's main /images/ folder.
    2. Change the code above to the following instead:
    Code:
      $(function() {
        $('FORM[name="quick_find"]')
          .submit(function() {
             $(this).find("input[type='submit']").attr("disabled", true).before('<img src="images/loadingsmall.gif" id="wait-image">');
          });
      });
    Last edited by DrByte; 26 Jul 2013 at 11:49 PM. Reason: variation
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Re: Need help fixing this sidebox search code from 'double submitting' the search.

    Thanks,

    This greys out the button wonderfully (no spinner though-using with either the top level images folder or the one in the template folder - no worries)

    This works great when 'clicking' on the button to grey it out. Is there any additional code that can also grey it if you press the Enter/Return key too? That method of submission still yield to clogging.

    Everything else was removed with my original attempted code.
    Jeff Michaels,
    pres of Musical Creations Ltd.

  4. #4
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Need help fixing this sidebox search code from 'double submitting' the search.

    Ya, the Return/Enter thing is a pain. Try this:
    Code:
      $(function() {
        $('FORM[name="quick_find"]')
          .submit(function() {
            $(this).children("input[type='submit']").attr("disabled", true);
            $(this).children('input[name="keyword"]').keypress(function(e){
              if (e.which == 13) e.preventDefault();
            });
          });
        });
    (again, using newer than jQuery 1.6 would switch to prop() instead of attr() -- and the keypress thing could then also be changed to use .bind('keypress', false) instead.)
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Re: Need help fixing this sidebox search code from 'double submitting' the search.

    Yeah! Success on 3 browsers (Safari, Chrome and Firefox). Disables repeated search submits on the button, Enter and Return keys. You the best man!
    Jeff Michaels,
    pres of Musical Creations Ltd.

  6. #6
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Re: Need help fixing this sidebox search code from 'double submitting' the search.

    I would like one modification if possible:

    Can I use a css button instead of a standard white 'submit' button on my website, and have it disable?

    Instead of using:
    PHP Code:
    <input type="submit" value="' . HEADER_SEARCH_BUTTON . '"  style="width: 50px" /> 
    with the .js code
    PHP Code:
          .submit(function() {
             $(
    this).find("input[type='submit']").attr("disabled"true); 

    I would like to use this button code:

    PHP Code:
    zen_image_submit (BUTTON_IMAGE_SEARCH,HEADER_SEARCH_BUTTON); 
    Jeff Michaels,
    pres of Musical Creations Ltd.

  7. #7
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Need help fixing this sidebox search code from 'double submitting' the search.

    Pretty sure no changes required. You weren't using a graphical button before anyway; yours was a browser-default button, so it was still called type="submit", just like the CSS button would be.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Aug 2006
    Location
    North Carolina
    Posts
    279
    Plugin Contributions
    0

    Default Re: Need help fixing this sidebox search code from 'double submitting' the search.

    Sorry no. The css button with multiple clicking clogs the search again.
    Jeff Michaels,
    pres of Musical Creations Ltd.

 

 

Similar Threads

  1. v139h I need help fixing alignment problem with my search box
    By Noodles1971 in forum General Questions
    Replies: 5
    Last Post: 16 Jan 2013, 03:06 PM
  2. Can I make the Search Sidebox Search the Titles Only ?
    By milobloom in forum General Questions
    Replies: 4
    Last Post: 30 Apr 2011, 06:20 AM
  3. I need category & products hidden from the Online Catalog from search engines
    By g00glethis1 in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 21 Jul 2010, 06:11 PM
  4. Replies: 2
    Last Post: 2 Feb 2010, 11:48 AM
  5. Need to put "search help?" into the search sidebox
    By jeffmic in forum Templates, Stylesheets, Page Layout
    Replies: 9
    Last Post: 30 Nov 2006, 11:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR