0

I am using SimpleCart & need a way to validate the data inputted by the user. I can't use the default button because simple cart needs to use it's own class. I know there's a way but I can't seem to make it work or find the answer. I basically need to assign some kind of validation to a click handler. Heres my code for SimpleCart

simpleCart({

    cartColumns: [
    { attr: "name", label: "Item"},
    { view: "decrement", label: false},
    { attr: "quantity", label: "Quantity"},
    { view: "increment", label: false},
    { view: "remove", text: "Remove", label: false}
    ],

    cartStyle: "table",

    checkout: {
    type: "SendForm" ,
    url: "orders.php",
    extra_data: {
    first_name: "document.getElementById('first-name').value()",
    last_name:  "document.getElementById('last-name').value()",
    email: "document.getElementById('email').value()",
    phone: "document.getElementById('phone').value()"
    }
    }
    });

    simpleCart.bind( 'beforeCheckout' , function( data ){
    data.first_name = document.getElementById("first-name").value;
    data.last_name = document.getElementById("last-name").value;
    data.email = document.getElementById("email").value;
    data.phone = document.getElementById("phone").value;
    });

and this is my jQuery for validation

$(document).ready(function() {
    $("#form").validate({  // initialize plugin on the form
    rules: {
    firstName: "required",
    lastName: "required",
    phone: "required",
    email: {
    required: true,
    email: true,
    },
    }
    });

This is the code to submit the data -- It's not the usual input submit

<a href="javascript:;" class="simpleCart_checkout submit">Submit Order</a>
Jackthomson
  • 644
  • 8
  • 23

1 Answers1

0

You may try this :

$('a[class=simpleCart_checkout]').on('click',function(e)
{
  if(!jquery.validate())
e.preventDefault();
});
DinoMyte
  • 8,737
  • 1
  • 19
  • 26