Forums

How to set up a coupon code

desertdiana 25 Jul, 2014
Hi,

I would like to add a required field for a coupon code input that is needed to submit. How do I do this?

Thank you for your help.

Diana
GreyHead 27 Jul, 2014
Hi Diana,

I would use Custom Serverside validation to check that the coupon code is valid.

Bob
desertdiana 27 Jul, 2014
Hi Bob,

I used this that I found in another post but if I put in something other than SUG2014 it still submits. Is there something I am missing?

Is there a way to have 3 or 4 coupon codes in the statement?

<?php
$promo_code = JRequest::getString('promo_code', '', 'post');
if ( $promo_code && $promo_code != 'SUG2014' ) {
      return "Sorry, that is an invalid promo code";
}
?>
GreyHead 27 Jul, 2014
Hi Diana,

I think that the V$ you have here is probably CFv4 . . . if it is then please see this FAQ

Bob
desertdiana 27 Jul, 2014
Yes, CFv4.........sorry typo

I added the code as in the Faqs but it doesn't work just throws the error message no matter what I put in the field.
GreyHead 28 Jul, 2014
HI Diana,

Exactly what code are you testing? The code in your previous post isn’t quite the same as the example in the FAQ.

Bob
desertdiana 28 Jul, 2014
I tried the code in the faqs post. I must need to do something else maybe in the field setting, but the faqs didn't address that. Here is what I used.

<?php
$ok_values = array(
  'sug2014', 
  'specialsug',
  'sugfree'
);
if ( !in_array($form->data['data'], $ok_values) ) {
  $form->validation_errors['data'] = "Sorry your promo code is incorrect. Please refer to your StandUpGirl Promo letter for the correct promo code";
  return false;
}
?>
GreyHead 28 Jul, 2014
Hi Diana,

That looks OK except that you have replaced 'promo_code' with 'data' What is the name of the input you are using for the promo code?

Bob
desertdiana 28 Jul, 2014
That was it Bob..................thank you! I just wasn't sure what to change in the code other than the promo codes themselves.

Works perfectly!

Cheers!

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