Email Form Plugin & Conditional Sending

mikeewart

New Member
Hi -

I hope someone can assist me. I am sure I just did something stupid and it is a trivial issue.

I am trying to have the form results sent to different email addresses based on a drop down selection.

It works fine if I have all of the results simply go to a list of emails but I need it to go to person A if they select X, person B if Y, etc.

I already tried to do it with the code in the wiki, changing the field names. I pasted the code from the wiki into the "Email to (eval)" field in the plugin.

Am I missing something?

Email addresses had the @ removed to allow posting

$reason = $this->data['register___reason'];
switch ($reason) {
case 'memberservice':
$email = 'mike ATdomainname.com';
break;
case 'loan':
$email = 'mike
AT domainname2.com';
break;
case 'mortgage':
$email = 'mike
AT domainname3.com';
break;
case 'other':
$email = 'info AT
domainname4.com';
break;
}
return $email;

Joomla version 3.4.1
Fabrik ver 3.3.2


Thanks,
Mike
 
If 'reason' is a dropdown, I suspect the data will be an array, so you'd probably want to put this as the second line:

Code:
$reason = is_array($reason) ? $reason[0] : $reason;

-- hugh
 
Thanks.

As an additional line like this?

$reason = $this->data['register___reason'];
$reason = is_array($reason) ? $reason[0] : $reason;
switch ($reason) {
 
I tried the above and got the following when I selected "Loans" in dropdown which has value of "loan"

string(5) "Loans" NULL

Any suggestions?
 
I've got also in trouble with this. I followed the tips above and got this message:

Code:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

I don't save to DB. The DropDown field contain only valid characters. This is the content of the email eval field:

Code:
$company = $this->data['___empfaenger'];
$company = is_array($company) ? $company[0] : $company;
  switch ($company) {
  case 'service':
    $email = 'info@swm-produktion.de';
    break;
  case 'netzbetreiber':
    $email = 'at@telefred.de';
    break;
  case 'loesungen':
    $email = 'mgb@telefred.de';
    break;
}
var_dump($company,$email);exit;
return $email;

Joomla! 3.4.3, Fabrik 3.3.2, PHP 5.3.29

I appreciate any help!
 
Fastserv: do you have the form in a popup?

mikeewart: seems you are getting the label which is not found in your "cases", so $email is NULL
compare with you labels or try to get the values with
$reason = $this->data['register___reason_raw'];
 
No popup but an ajaxfied form in a modul...
The error message is because of the var_dump output (you can see it in the network response), which is breaking the expected JSON.
Same as with mikeewart
the var_dump is
string(7) "Service" NULL
you are testing for 'service' so $email is undefined.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top