Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2012
    Posts
    13
    Plugin Contributions
    0

    Default Restrict Qty Box input to numbers

    It seems that letters can be entered into Qty boxes by default in Zen Cart. While I doubt this flows through to the shopping cart, wouldn't it make sense to restrict the input to numbers only??

    Does anybody have an idea how to do this??

    I assume it would be similar for product list and product info pages.
    I tried changing the input type from text to number in product_listing.php

    $lc_button= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($listing->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $listing->fields['products_id']), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($listing->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $listing->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) .
    '</form>';

    but that didn't work. Any suggestions?

  2. #2
    Join Date
    Apr 2012
    Location
    beijing
    Posts
    258
    Plugin Contributions
    1

    Default Re: Restrict Qty Box input to numbers

    if input letters ,it won't work when click "add to cart"
    focus on the open source for online shoping website.
    my site: best shop 24h.com

  3. #3
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Restrict Qty Box input to numbers

    Quote Originally Posted by wacamatic View Post
    It seems that letters can be entered into Qty boxes by default in Zen Cart.
    There's nothing particularly unusual about this.

    Quote Originally Posted by wacamatic View Post
    While I doubt this flows through to the shopping cart, wouldn't it make sense to restrict the input to numbers only??
    Yes, if it were possible.

    Quote Originally Posted by wacamatic View Post
    Does anybody have an idea how to do this??
    It isn't possible to do this via the HTML input fields. (see note below)
    It can be done by adding a bit of javascript though. (which can perform the check client side)

    Quote Originally Posted by wacamatic View Post
    I tried changing the input type from text to number in product_listing.php
    but that didn't work.
    That is because 'number' isn't a valid input type. An input element can be of type text field, checkbox, password, radio button or submit button.

    Numbers need to be entered using the 'text' type, and it is left for the server side code to check for validity... Alpha characters (non numerics) will resolve to a numeric value of 'zero', so if someone enters a 'Q' instead of a number it is as though they entered a zero. (a valid number)

    *Note: HTML5 has several new input types for forms. These new features allow better input control and validation.

    • color
    • date
    • datetime
    • datetime-local
    • email
    • month
    • number
    • range
    • search
    • tel
    • time
    • url
    • week

    Note: Not all major browsers support all the new input types. However, you can already start using them; If they are not supported, they will behave as regular text fields.


    So, with HTML5 there is a solution, and the method you tried will/should work (at least with some browsers). It may be too early to be able to actually depend on it though, so javascript and/or serverside validation is still needed for the time being.

    Cheers
    Rod

  4. #4
    Join Date
    Nov 2012
    Posts
    13
    Plugin Contributions
    0

    Default Re: Restrict Qty Box input to numbers

    Thanks Rod. I was reading a bit about the input types in HTML5 which is where I got the idea. Thanks for pointing towards javascript as a possible solution.

    Warren

 

 

Similar Threads

  1. v139h Restrict QTY Discounts To Same Shipping Address
    By sparrowce in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 2
    Last Post: 18 Feb 2015, 12:51 AM
  2. Display Attributes/Options, Qty Discounts & Qty Box in Matrix
    By teaj in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 21 Apr 2011, 02:59 PM
  3. Extra 'input' box needed on product info input page
    By abaris in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 1 Apr 2009, 03:40 PM
  4. Remove original qty box and add my own option and input in description
    By ivogue in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 2 Mar 2009, 11:45 PM

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