Title: Code for Client Side Validation
Last modified: September 1, 2016

---

# Code for Client Side Validation

 *  [carver1g](https://wordpress.org/support/users/carver1g/)
 * (@carver1g)
 * [9 years, 10 months ago](https://wordpress.org/support/topic/code-for-client-side-validation/)
 * I have some impatient customers that multiple click on the woocommerce add-to-
   cart button so rather than disabling the button after form submission I have 
   created a fake disabled button that states ‘Adding to cart. Please wait…’. Through
   the use of jquery, when a customer clicks on the normal add-to-cart button, that
   button is hidden and my fake button shows. By use of css the fake button is located
   in the exact same position as the real add-to-cart button so no one is any the
   wiser and I think this method is cross browser friendly.
 *  This works great for simple and variable products to prevent multiple submissions
   but custom products with required fields is another story. My custom products
   have two required fields. One is a text field (name) the other is radio buttons(
   yes or no answer). With ‘Client Side Validation’ disabled when a customer clicks
   on the real add-to-cart button that button is hidden and my fake button shows.
   If there is an error the fake button is then hidden and the real add-to-cart 
   button shows allowing the customer to correct any errors and resubmit. Upon correction
   of errors and resubmission, the real button is hidden and the fake button shows.
 *  With Client Side Validation enabled when a cutomer clicks on the real button
   and there is an error, my error message shows next to the field, as it is suppose
   to, and my fake add-to-cart button is shown but then it all stops there not allowing
   the customer to correct any errors and unable to resubmit. I surmise the error
   message appears before the form is actually submitted for validation so herein
   lies my problem.
 *  I prefer using the Client Side Validation so the customer knows exactly where
   the error occurred without jumping to the top of the page and without having 
   to scroll back down and try to find the problem. The Client Side Validation feature
   of your plugin is exactly what I need for my type of customized products. Excellent
   feature.
 *  Is there any way this code I am using to show and hide the buttons can be modified
   to work with the Client Side Validation? Possibly triggering when the error message
   appears? Or maybe an all together better code?
 * //hide/show add to cart buttons
 * jQuery(document).ready(function ($) {
    $(‘form.cart’).submit(function(){ var 
   errors = []; if(errors.length > 0){ $(“#btnone”).show(); $(“#btntwo”).hide();}
   else{ $(“#btnone”).hide(); $(“#btntwo”).show(); } }); });
 * Or maybe you could make something like this as part of your premium plugin of
   which I’ll be first in line to purchase even without this feature!
 * Any help on this one will be very much appreciated.
    Thanks
 * [https://wordpress.org/plugins/wc-fields-factory/](https://wordpress.org/plugins/wc-fields-factory/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Saravana Kumar K](https://wordpress.org/support/users/mycholan/)
 * (@mycholan)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/code-for-client-side-validation/#post-7525214)
 * Hi Carver,
 * Long time. yes this is a very good suggestion, disable the Cart button whenever
   an error on the custom fields.
 * Like in the variable product if you don;t choose any option the Cart button will
   be on the disabled state, once you selected the option it will be enabled instantly.
 * But you also wanted to disable the Cart button once the user hit it, so that 
   we can prevent multiple clicking.
 * I will try to include these as an option.
 * and Yes the Premium version is also almost ready, will let you know soon.
 * Regards
    Sark

Viewing 1 replies (of 1 total)

The topic ‘Code for Client Side Validation’ is closed to new replies.

 * ![](https://ps.w.org/wc-fields-factory/assets/icon-128x128.jpg?rev=2738843)
 * [WC Fields Factory](https://wordpress.org/plugins/wc-fields-factory/)
 * [Support Threads](https://wordpress.org/support/plugin/wc-fields-factory/)
 * [Active Topics](https://wordpress.org/support/plugin/wc-fields-factory/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wc-fields-factory/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wc-fields-factory/reviews/)

## Tags

 * [code](https://wordpress.org/support/topic-tag/code/)
 * [validation](https://wordpress.org/support/topic-tag/validation/)

 * 1 reply
 * 2 participants
 * Last reply from: [Saravana Kumar K](https://wordpress.org/support/users/mycholan/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/code-for-client-side-validation/#post-7525214)
 * Status: not resolved