Can anyone provide a snip of code that I could insert into the "coupon code" field on a formmail form which has the following effect:
on submit form, user goes to the normal payment page (this is already implemented)
if coupon code field is filled out with correct code, user is taken to alternate payment page on form submit.
Either this or another approach which has the same result is OK. I am a novice coder working in a wysiwyg - I don't REALLY know php at all - I just need a snip I can insert and a clear instruction.
Thanks so much for any help.
Coupon code form field redirect to alternate payment page
Moderator: General Moderators
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: Coupon code form field redirect to alternate payment pag
Could you post your script up please (removing any passwords/email addresses, etc.) because it's difficult to tell you where the code needs to go when we don't know how your scripts work, how many of them there are, etc. Also, you don't say what the coupon code is being checked against - is this a value stored in a file, a database? - and how the values are passed between the different forms/scripts.
I'll provide some snippets of code to get you started and you can let me know if this is what you're looking for
Note that I haven't added any form validation where the $_POST value is being captured - this is just an example so you know what you need to look for in your own scripts.
HTH,
M_G
I'll provide some snippets of code to get you started and you can let me know if this is what you're looking for
Code: Select all
$coupon_code = $_POST['coupon_code']; // this captures the value being sent from the form
if ($coupon_code == $some_other_value) {
// the coupon code is valid
$redirected_address = 'Location: http://www.blahblah.com/valid_coupon_page.php';
header ($redirected_address);
exit();
} else {
// the coupon code isn't valid, go to the default page
$redirected_address = 'Location: http://www.blahblah.com/default_page.php';
header ($redirected_address);
exit();
}HTH,
M_G
Re: Coupon code form field redirect to alternate payment pag
Thanks for the reply!
I could post my page code, but it's a long complex page and that may not be necessary.
It is all composed strictly in Wysiwyg Web Builder 6, and I am not a proficient coder, though I can & do make small edits to my pages.
The page is published as a php page, because of the form I use. The form is a pretty straightforward form-mail form, which submits on click of the "continue" button - then the user is brought to the payment page. Location of the payment page is right there in the form code section.
What I want is to make the contents of the "coupon code" textbox field to cause a redirect to a different payment page on submit click: depending on what was entered. I only really need one active coupon code at a time, which would have this effect if entered correctly - and the active coupon code would change from time to time. If I could get functionality for several active coupon codes, this would be great - but that's not critical.
I thought I could just insert a script for this purpose between, before, or after the tags of the coupon code textbox field, which I can easily do just by right clicking my textbox object from within my wysiwyg composer.
Thanks for any help!
I could post my page code, but it's a long complex page and that may not be necessary.
It is all composed strictly in Wysiwyg Web Builder 6, and I am not a proficient coder, though I can & do make small edits to my pages.
The page is published as a php page, because of the form I use. The form is a pretty straightforward form-mail form, which submits on click of the "continue" button - then the user is brought to the payment page. Location of the payment page is right there in the form code section.
What I want is to make the contents of the "coupon code" textbox field to cause a redirect to a different payment page on submit click: depending on what was entered. I only really need one active coupon code at a time, which would have this effect if entered correctly - and the active coupon code would change from time to time. If I could get functionality for several active coupon codes, this would be great - but that's not critical.
I thought I could just insert a script for this purpose between, before, or after the tags of the coupon code textbox field, which I can easily do just by right clicking my textbox object from within my wysiwyg composer.
Thanks for any help!
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: Coupon code form field redirect to alternate payment pag
Hi again,
I appreciate the script might be quite long but it would be worth posting it up if you can because it will probably be obvious exactly where the new code needs to go - the example that I provided before should do what you need but I'd need to see your script to know where it needs to go. Adding multiple coupon values would be straightforward enough - you could just use switch() as in this example:
Is the form displayed and processed using the same script? Also, I asked this before I think but how do the values from the form get sent to the new script when the page is redirected?
Another option if you want the page to automatically redirect as soon as someone enters something in the 'coupon code' part of the form is to use JavaScript but this seems unintuitive (to me at least) so it would be better to evaluate the coupon value in the PHP script and redirect from there.
HTH,
M_G
I appreciate the script might be quite long but it would be worth posting it up if you can because it will probably be obvious exactly where the new code needs to go - the example that I provided before should do what you need but I'd need to see your script to know where it needs to go. Adding multiple coupon values would be straightforward enough - you could just use switch() as in this example:
Code: Select all
switch ($coupon_code) {
case 'SEPT001':
$redirected_address = 'Location: http://www.blahblah.com/valid_coupon_page_for_september.php';
break;
case 'OCT001':
$redirected_address = 'Location: http://www.blahblah.com/valid_coupon_page_for_october.php';
break;
default:
$redirected_address = 'Location: http://www.blahblah.com/default_page.php';
break;
}
header ($redirected_address);
exit();
Another option if you want the page to automatically redirect as soon as someone enters something in the 'coupon code' part of the form is to use JavaScript but this seems unintuitive (to me at least) so it would be better to evaluate the coupon value in the PHP script and redirect from there.
HTH,
M_G