Validation plugin - insert into MySQL

Validation plugin - insert into MySQL

Hi everybody,

I'm trying to insert form data into MySQL database after validation. I understand that I need to pass the data to server-side script, like this one:

  1. $(document).ready(function(){
  2. $("form#submit").submit(function() {
  3. // we want to store the values from the form input box, then send via ajax below
  4. var fname     = $('#fname').attr('value');
  5. var lname     = $('#lname').attr('value');
  6. $.ajax({
  7. type: "POST",
  8. url: "ajax.php",
  9. data: "fname="+ fname +"& lname="+ lname,
  10. success: function(){
  11. $('form#submit').hide(function(){$('div.success').fadeIn();});

  12. }
  13. });
  14. return false;
  15. });
  16. }); 
But, I don't get it, where should I put code like this? Validation function looks like this:

  1. $().ready(function() {
  2. // validate the comment form when it is submitted
  3. $("#commentForm").validate();
  4. // validate signu
  5. $("#signupForm").validate({
  6. rules: {
  7. firstname: "required",
  8. lastname: "required",
  9. },
  10. messages: {
  11. firstname: "Please enter your firstname",
  12. lastname: "Please enter your lastname",
  13. }
  14. });
Thanks