Forums

How to use Redirect Plugin AND do custom validation?

edog5948 12 Apr, 2011
Here's what I'm trying to do:
User wants to purchase a coupon.
There is a limit to the total number of coupons available.
If the user intends to purchase more than the remaining number of coupons, display an error message and user ends up back at the form to try a smaller amount for purchase.
If the user intends to purchase coupons and there are still enough remaining coupons, redirect the user to PayPal for purchase.

I have a very simple form and I'm using the Redirect Plugin for getting to PayPal.
This is working very well.

Now, I need to put in the code that calculates whether or not the number of coupons the user requests are available.

As a simple test, I followed http://www.chronoengine.com/forums.html?cont=posts&f=2&t=11560&p=17018#p17018 and made a simple test:
On the form General tab: Form tag attachment: onSubmit="return Validate()"
On the form Form Code, Form Javascript:
function Validate(){
    if(1 != 2){
    alert('Your passwords do not match');
    return false;
    }else{
    return true;
    }
}


I had expected the alert message to pop, but it did not.
Instead the redirect to PayPal happened.

How can I perform the check on number of coupons requested before redirecting to PayPal?
GreyHead 12 Apr, 2011
Hi edog5948 ,

Your code works here, so something else is going on. Please post a link to the form so we can take a quick look.

Bob
edog5948 12 Apr, 2011
PM posted earlier today.
GreyHead 13 Apr, 2011
Hi edog5948,

I can't track having received an email or a PM from you.

Bob
edog5948 13 Apr, 2011
OK. Reposted PM to you.
GreyHead 13 Apr, 2011
Hi edog5948,

Are you sending them to Admin? That's not me. Click the PM link under my picture please.

Bob
edog5948 13 Apr, 2011
OK. Sent through email this time.
edog5948 13 Apr, 2011
And - looks like the PM went through now, too.😉
GreyHead 13 Apr, 2011
Hi edog5948,

Got it now thank you - in many copies :-)

It's fixed - when I looked at the form I remembered that we'd seen this problem once before. When LiveValidation is enabled it hijacks the 'onSubmit' event so your script is never fired.

I've added an id='submit' to the submit input and added a code snippet to call the Validate function when it is clicked. This happens before the submit so it fires OK.

Bob
edog5948 13 Apr, 2011
Great! I'll go take a look at it.
edog5948 14 Apr, 2011
OH, so close...

The alert triggers (as expected), but the redirect continues on (not wanted).
When the alert triggers, I need to take the user back to the original form, not get redirected on.

Any ideas?
GreyHead 18 Apr, 2011
Hi edog5948,

Try adding another line of code to disable the submit button?

Bob
This topic is locked and no more replies can be posted.