Up to 50 percent off

Form Validation

This topic contains 3 reply and 2 voices, and was last updated by Tareq Hasan 10 years, 10 months ago
Viewing 3 Posts - 1 through 3 (of 3 total)
Author Posts
January 3, 2014 at 12:04 pm 14110
Tareq Hasan I have 6 fields that I need the user to input at least one before the form can submit. I've attempted to do this with jQuery however the form is still submitting and I think this is due to the ajax submission. I can't put the required attribute because only one of them is and it could be any one. Is there a way I can say if fields 1-6 are empty, add a notice to the form and stop submission? Also I have searched to find an answer to this on this forum but I can't. I am using this plugin to allow users to submit woocommerce products and I have a few number fields. I saw you mentioned a number field but I do not have a number field for a custom field. I am using the latest 2.1.8 pro version. Thanks.
January 8, 2014 at 7:37 am 14233
Jamie Jamie

Anyone?

January 8, 2014 at 10:03 am 14235
Jamie Jamie

Turns out I was able to make this work.

For those that need to know how to do this kind of validation I used the following jQuery

$('.wpuf-submit input').click(function(){ 
    var test_val = $.trim($('#input_id_here').val());
    var test_val2 = $.trim($('#input_id2_here').val());
    if ((test_val === '') && (test_val2 === '') { 
        $('.wpuf-form').append('<li class="has-error">Put your validation error in here.</li>'); 
       return false; // stops the form submitting. 
    }
});

You just add as many text inputs as you need and add them to the if statement.

January 8, 2014 at 12:14 pm 14236
Tareq Hasan Tareq Hasan

Hi Jamie, sorry I hadn’t noticed this topic. Glad to know that you were able to solve this by yourself.

Viewing 3 Posts - 1 through 3 (of 3 total)