close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Preventing decimals in quantity field

Thread began 3/26/2019 1:27 pm by TroyD | Last modified 3/27/2019 4:28 pm by Ray Borduin | 29 views | 2 replies |

TroyD

Preventing decimals in quantity field

I have a shopping cart that sells items in bags of 50. If you need more than 50, you simply buy another bag.
My calculations work by multiplying the (bag qty) x (qty in bag) x (individual price). All works fine, but a customer figured out a way to buy 60 by entering 1.2 in the quantity.

There is javascript that prevents this but if you disable javascript for a moment, you can enter and post quantities of 1.2, 1.5, or whatever you want. Long story short, I needed to restrict the quantity to whole numbers, 1, 2, 3, etc with and without javascript.

I found one solution in a previous thread where Ray recommended changing floatval to intval for the $itemQuantity in the eCart object. This worked great but if I open and edit the eCart object interface at a later date, it resets the intval back to floatval. If I forget to go back and manually change it again, then we have the same issue.

Then I thought, why not try using floor() for my qty post value in the Add To Cart behavior. This works fine when adding a product to the cart. Is there any reason I can’t just use this method?

This is what I changed in the ATC behavior.

Changed this…

php:
$ATC_itemQuantity = "".$_POST["eCart1_1_Quantity_Add"]  ."";// column binding


To this…

php:
$ATC_itemQuantity = "".floor($_POST["eCart1_1_Quantity_Add"])  ."";// column binding


Is this acceptable? I didn’t want to add this to the live site until I was certain it wouldn’t cause some other side affect.

Thanks
TroyD

Sign in to reply to this post

Ray BorduinWebAssist

That will work and won't cause any issues.

Sign in to reply to this post

TroyD

Thank Ray.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...