0

I am setting up validation following the tutorial at link text

My form action script is as follows:

<form method="POST" action="formproc_to_paypal.php" id="example"
     target="_self" onsubmit="CalcAmount (this); ReadForm(this);" name="example">

When I remove/change the action line to "" (as the tutorial shows) the validation works fine. Any idea why the action is causing it not to validate?

  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
<style type="text/css">
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
em { font-weight: bold; padding-right: 1em; vertical-align: top; }
</style>
  <script>
  $(document).ready(function(){
    $("#example").validate();
  });
  </script>
4
  • Could post some more details, like the validation logic? My initial guess is you're calling two validation functions on submit, and if the first works it'll skip the second. But it's hard to say without details... Commented Jun 15, 2009 at 18:51
  • Mike, you might be correct. In my PHP script I have a similar function, the PHP script calls the form variables and then forwards them to PayPal. Would this interfere with the validation? Commented Jun 15, 2009 at 19:21
  • I think Mike is right. Your explicitly-defined onsubmit events might be breaking the validate() function called via jQuery. Try taking them out and see what happens? Also keep in mind the tutorial has no action attribute because it's not a live form. Read through the rest of the documentation since the "tutorial" isn't really a good example of a real implementation. Commented Jun 15, 2009 at 19:22
  • This makes sense - but how would I have 2 call variables if I need them both. Is that even possible? Commented Jun 15, 2009 at 19:27

2 Answers 2

1

Be sure to do a return false after every javascript call, otherwise when the javascript is done, the is submitted to the action.

that is also why it works if there is no action specified.

Sign up to request clarification or add additional context in comments.

Comments

0

Something like this

function validate(form){
 return(CalcAmount (form) && ReadForm(form));
}

Keep in mind this a very quick implementation, you might have to add some more details. The general idea is have one function that returns a single boolean based on a combination of results.

Comments