Event Switcher with coupon code

How to send form data to different recipients based on coupon codes in ChronoForms.

Overview

The issue occurs because the form needs to route emails to specific addresses depending on the coupon code entered, but the Event Switcher action is not suitable for this task.
Use a Custom Code action to map coupon codes to email addresses and set a dynamic variable, then reference that variable in the Email action's Dynamic To field.

Answered
sa saddys 18 Mar, 2016
Good morning, I would kindly understand if it is possible to have a form with these features:

- Name, surname, email, coupon code

I would like to associate a coupon to an email, example:

coupon "1234" to xx@xx.it
coupon "5678" to yy@yy.it
coupon "9876" to zz@zz.it
etc. etc

Now, when a person writes in the form name, surname, email (ie gabriele@xx.it), coupons 1234, I would like:

- The site administrator receives the form data
- Gabriele@xx.it receives the form data
- Xx@xx.it receives the form data

If the person enters the coupon 5678:

- The site administrator receives the form data
- Gabriele@xx.it receives the form data
- Yy@yy.it receives the form data

etc etc...

it's possible? I tried EVENT SWITCHER but I can not find a php code that does this job.

thank you
Gr GreyHead 19 Mar, 2016
Answer
1 Likes
Hi saddys,

You don't need an Event Switcher for this; you can use a Custom Code action before the Email action with code something like this
<?php
$coupons = array (
  '1234' => 'xx@xx.it',
  '5678' => 'yy@yy.it',
  '9876' => 'zz@zz.it',
);
$email_to = '';
if ( !empty($form->data['coupon']) && array_key_exists($form->data['coupon'], $coupons) ) {
  $email_to = $coupons[$form->data['coupon']];
}
$form->data['email_to'] = $email_to;
?>
Then use email_to (with no quotes or brackets) in the Dynamic To box of the Email action.

Bob

[[>> updated to fix error <<]]
sa saddys 20 Mar, 2016
Thanks for reply. I try with no success.

This is the debug (i mask email and IP):

Data Array

Array
(
    [option] => com_chronoforms5
    [chronoform] => bigliettocoupon
    [event] => submit
    [nome] => Gab
    [cognome] => Cir
    [email] => (gabriele AT email)
    [coupon] => 5678
    [button4] => Invio dati
    [email_to] => 
    [ip_address] => xx.xxx.xxx.130
)

Array
(
)

Errors

Array
(
)

Debug Info

Array
(
    [0] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:, gabriele AT my email
                    [2] => Subject:Prova invio biglietto
                    [3] => From name:Gabriele
                    [4] => From email:gabriele AT my email
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:Gabriele
                    [8] => Reply email:gabriele AT my email
                    [9] => Attachments:
                    [10] => Array
                        (
                        )

                    [11] => Body:
<table>
<tr><td>Nome</td><td>Gab</td></tr>
<tr><td>Cognome</td><td>Cir</td></tr>
<tr><td>Email</td><td>gabrielexxxxxxxxxxxxxxxx</td></tr>
<tr><td>Codice coupon</td><td>5678</td></tr>
</table><br /><br />IP: xxxx.130
                )

        )

)
Gr GreyHead 20 Mar, 2016
Hi saddys,

Sorry. I think that needs to be array_key_exists() and not in_array() - I've updated my earlier post.

Bob
sa saddys 21 Mar, 2016
Now it works perfectly!

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