1

I have worked some recapthca into my web form and want to maintain the client side form validation. As the form currently is

  <form action="ajax/ajax_repSubTesting.php" method="POST" name="submitform" onSubmit="checkform(this)">

checkform() is a series of if/else statements to inform the user that a data field is either blank or not valid. Problem is that once the submit button is clicked , the checkform is called popping up an error window, and once closed the ajax script is called.

How would I code this so that the form action is dependent on everything in checkform() validated properly?

Christopher Law
  • 189
  • 1
  • 1
  • 7
  • The issue is that the Ajax method is not dependent on the result of the checkform function. Show us all of your javascript. – Ohgodwhy Apr 02 '16 at 22:51
  • 1
    See http://stackoverflow.com/questions/3350247/how-to-prevent-form-from-being-submitted – 4castle Apr 02 '16 at 22:53

2 Answers2

2

Returning false from an inline onsubmit event handler will will cancel the form submission. The checkform function should return false (as appropriate) for invalid form data

function checkform () {
   if (!valid) { return false; }
   // ..
}

and the returned value must be propagated through the inline event handler

<form .. onsubmit="return checkform()">
                   ^^^^^^

See also

(Also, 'ajax' is normally called via XHR, not form submission.)

Community
  • 1
  • 1
user2864740
  • 60,010
  • 15
  • 145
  • 220
0

try adding id to the submit button and yhe form itself. Then at the beginning of the validation method add event.preventDefault(); Which will cancel the form submition.

Then at the end of the validation method if the form is valid add the next jQuery method: $('form').submit() it will trigger form submition.

Tomer Klein
  • 436
  • 2
  • 6