Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Nov 2005
    Location
    France
    Posts
    579
    Plugin Contributions
    8

    Default Prevent spaces being used to fill text input attribute

    I have a problem where clients occasionally just press the enter key rather than input text into an attribute field.
    In some circumstances this may not be a problem, but in this instance it is.

    The problem with the zen cart check on text required is that it sees a space as a character, so pressing the spacebar alone will circumnavigate the zc check.

    I know i can use something along the lines of:

    $("input#attrib-2-0").on({
    keydown: function( e ) {
    if (e.which === 32)
    return false;
    },
    change: function() {
    this.value = this.value.replace(/\s/g, "");
    }
    });
    which will stop the spacebar being used, and i assumed that putting attrib-2-0 as the input name (this is the name shown when inspecting the element with firebug) would do the trick.
    However, no matter where i try to put this code, that attribute field will still allow a space to be entered.

    I know the code is good because i tested it in jsfiddle here: http://jsfiddle.net/EJFbt/1/

    I have tried adding the code into includes/modules/attributes.php, includes/templates/custom_template/templates/tpl_modules_attributes.php, includes/templates/custom_template/templates/tpl_product_info_display.php,
    includes/templates/custom_template/common/html_header.php directly, and also as a file in jscript.

    Every time, it still allows the spacebar to function in the field that is shown as
    <input id="attrib-2-0" type="text" value="" maxlength="128" size="32" name="id[txt_2]">

    I even tried id[txt_2] instead of attrib-2-0

    Please, any suggestions before i tear out what remaining hair i have!!

    Thanks

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Prevent spaces being used to fill text input attribute

    You could try editing the shopping_cart class around line 1685 ...
    Code:
          if (isset($_POST['id'])) {
            foreach ($_POST['id'] as $key => $value) {
              $check = zen_get_attributes_valid($_POST['products_id'], $key, TRIM($value));
              if ($check == false) {
                $the_list .= TEXT_ERROR_OPTION_FOR . '<span class="alertBlack">' . zen_options_name($key) . '</span>' . TEXT_INVALID_SELECTION . '<span class="alertBlack">' . (zen_values_name($value) == 'TEXT' ? TEXT_INVALID_USER_INPUT : zen_values_name($value)) . '</span>' . '<br />';
              }
            }
          }
    and see if that doesn't solve the problem ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #3
    Join Date
    Nov 2005
    Location
    France
    Posts
    579
    Plugin Contributions
    8

    Default Re: Prevent spaces being used to fill text input attribute

    Thank you Ajeh. Trim did the trick.
    Simple solutions are always the best :)

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Prevent spaces being used to fill text input attribute

    Thanks for the update that this was able to work for you ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  5. #5
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Prevent spaces being used to fill text input attribute

    Quote Originally Posted by Ajeh View Post
    You could try editing the shopping_cart class around line 1685 ...
    Code:
          if (isset($_POST['id'])) {
            foreach ($_POST['id'] as $key => $value) {
              $check = zen_get_attributes_valid($_POST['products_id'], $key, TRIM($value));
              if ($check == false) {
                $the_list .= TEXT_ERROR_OPTION_FOR . '<span class="alertBlack">' . zen_options_name($key) . '</span>' . TEXT_INVALID_SELECTION . '<span class="alertBlack">' . (zen_values_name($value) == 'TEXT' ? TEXT_INVALID_USER_INPUT : zen_values_name($value)) . '</span>' . '<br />';
              }
            }
          }
    and see if that doesn't solve the problem ...
    How could this solution be implemented for the comments box during checkout - given that certain conditions to enter something are already in place?

    IOW, as it stands, if the customer is asked to enter some info into the comments box and omits to do so, they can not proceed further until they provide the requested info. That's how I have got it working at present. BUT they can still enter spaces into the box and are free to complete checkout.

    Most do, but there is always the odd one who pretends to be smarter by putting in blanks - resulting in time wasting email exchanges or even a refund as the requested info can not be provided.

    Thanks
    Last edited by frank18; 24 Mar 2014 at 02:41 PM.

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Prevent spaces being used to fill text input attribute

    What is your code that you use to make sure something is entered currently?
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  7. #7
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Prevent spaces being used to fill text input attribute

    Quote Originally Posted by Ajeh View Post
    What is your code that you use to make sure something is entered currently?
    Thanks Ajeh

    This file is loaded by the various checkout pages:

    PHP Code:
    <?php
    /** 
     * practitioner_alert.php
     * Loaded automatically by index.php?main_page=shopping_cart, index.php?main_page=checkout_shipping
     * and index.php?main_page=checkout_payment
     * 
     * Checks if restricted practitioner only items are in cart 
     * 
     * @package essential part of plug-in for Zen Cart - all versions 
     * @copyright Copyright 2012 Frank Riegel (frank18) www.isonetwork.net.au 
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 
     * @version $Id: practitioner_alert.php 2012-11-05 06:19:52Z frank18 $
     * @developed by: Frank Riegel (frank18) www.isonetwork.net.au 
     */
     
    // check if restricted practitioner only items are in cart
    // change the next lines to suit the ID's of your manufacturers
    // to add more manufacturers simply clone a line and add it to the script

    global $cart
    $chk_single_manufacturer $_SESSION['cart']->in_cart_check('manufacturers_id','1'); 
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','2'); 
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','4'); 
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','5'); 
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','8'); 
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','13'); 
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','14'); 
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','15');
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','22'); 
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','23');
    $chk_multi_manufacturers += $_SESSION['cart']->in_cart_check('manufacturers_id','38');

    ?>

    Then, in includes/modules/pages/checkout_payment/header_php.php the following changes were applied:

    PHP Code:
    // if cart contains restricted products and comments box is empty, redirect the customer to the shipping method selection page 
    require(DIR_WS_INCLUDES 'practitioner_alert.php'); 
    if (
    $chk_single_manufacturer) { 
          
    $prac_details '1'
    } elseif (
    $chk_multi_manufacturers) { 
          
    $prac_details '2'
    } else { 
          
    $prac_details '0'

    if (!
    $_SESSION['comments'] && $prac_details != '0') { 
        
    $messageStack->add_session('checkout_shipping'ERROR_NO_PRACTITIONER_DETAILS'error'); 
        
    zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING'''SSL')); 

     
    // avoid hack attempts during the checkout procedure by checking the internal cartID..... etc etc etc 
    And in includes/templates/bentley_classic/templates/tpl_checkout_payment_default.php the customer is getting some alerts / messages depending of what is the cart.

    Code:
          // ** END PAYPAL EXPRESS CHECKOUT ** ?>
    
    <!--bof prescriptive advice required alert --> 
    <div> 
    <?php 
    require(DIR_WS_INCLUDES . 'practitioner_alert.php'); 
    if ($chk_single_manufacturer) { 
      echo TEXT_PRESCRIPTIVE_ADVICE_REQUIRED; 
    } elseif ($chk_multi_manufacturers) { 
      echo TEXT_PRACTITIONER_ONLY_CHECKOUT; 
    } else {
        echo TEXT_NO_PRACTITIONER_DETAILS_REQUIRED;
        } 
    ?> 
    </div>
     
    <fieldset> 
    <legend> 
    <?php if ($chk_single_manufacturer) { 
      echo TABLE_HEADING_PRAC_DETAILS; 
    } elseif ($chk_multi_manufacturers) { 
      echo TABLE_HEADING_PRAC_DETAILS; 
    } else { 
        echo TABLE_HEADING_COMMENTS; 
        } 
    ?> 
    </legend> 
    <!--eof prescriptive advice required alert --> 
     
    <?php echo zen_draw_textarea_field('comments', '45', '3'); ?> 
    </fieldset>
    I have not included the various language defines in this post .....

    Has been working well except for the 'blanks'

    Thanks / Frank

  8. #8
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Prevent spaces being used to fill text input attribute

    What if in the header_php.php files of the checkout_whatever pages you trim the comments on:
    Code:
        $comments = trim($_SESSION['comments']);
    Code:
        $_SESSION['comments'] = zen_db_prepare_input(trim($_POST['comments']));
    would that accomplish what you are needing?

    Either that or in your code:
    Code:
    $_SESSION['comments'] = trim($_SESSION['comments']);
    if (!$_SESSION['comments'] && $prac_details != '0') { 
    
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today: v1.5.5]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  9. #9
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Prevent spaces being used to fill text input attribute

    Quote Originally Posted by Ajeh View Post
    What if in the header_php.php files of the checkout_whatever pages you trim the comments on:
    Code:
        $comments = trim($_SESSION['comments']);
    Code:
        $_SESSION['comments'] = zen_db_prepare_input(trim($_POST['comments']));
    would that accomplish what you are needing?

    Either that or in your code:
    Code:
    $_SESSION['comments'] = trim($_SESSION['comments']);
    if (!$_SESSION['comments'] && $prac_details != '0') { 
    
    Thanks Ajeh, I try that in the morning, beddies for me - it's midnight...

  10. #10
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Prevent spaces being used to fill text input attribute

    Chose this option


    PHP Code:
    $_SESSION['comments'] = trim($_SESSION['comments']); if (!$_SESSION['comments'] && $prac_details != '0') { 
    Works just fine - Thank You

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Can I prevent discount codes from being used on Special items that are on sale?
    By 4130 in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 1
    Last Post: 13 Jun 2013, 10:28 PM
  2. v150 Prevent coupons from being used by member groups
    By gtgeorge in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 1
    Last Post: 29 Jun 2012, 12:28 PM
  3. Pre fill text attribute
    By Phil020782 in forum Setting Up Categories, Products, Attributes
    Replies: 6
    Last Post: 30 Jul 2007, 10:37 AM
  4. How do I prevent a multi-line text box from being as wide as the page?
    By aaelghat in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 20 Apr 2007, 03:21 PM

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