Dynamic Email Fields

maspegren 20 Jan, 2014
I am using Chronoforms 4.0 on J2.5. I installed the Email [GH] action so I can use dynamic email. I added a Email[GH] action to the onSubmit inside of the Custom Server Side Validation action. I would like the email to go to an email I find in the DB based on some form fields. In the Custom Server Side Validation I added
$query = "SELECT j25_registrants.email FROM j25_registrants, j25_field_values WHERE j25_registrants.id = j25_field_values.registrant_id AND j25_field_values.field_value = '{$form->data['learners_permit_number']}';";
$db->setQuery($query);
$email = $db->loadResult();
JRequest::setVar('user_email',$email);


Then I put {user_email} in the "To" field of the Email[GH] action. The SQL statement works correctly, but I can't get the "To" field to be correct.

When I put in a debugger the "To" field under Email is empty. Any ideas?

Also, I used the same method as above to grab another field that I would like to display within the email body. But this isn't showing either. I would guess these two variables have the same issue.
maspegren 20 Jan, 2014
Here's my debug data, with some text changes to protect privacy:
Debug Data

Email errors
No valid To Email address found
Email info
Email send stopped.
From: (business name) email@domain.com
To:
Subject: Form Information
Email body
Here is your information:

Location: School
Dates: Mar 13-15, 2014
Number H12345678
Instructor {instructor}
GreyHead 21 Jan, 2014
HI maspegren,

The JRequest syntaxt was OK for CFv3 but won't work in CFv4. Please use this instead:
$form->data['user_email'] = $email;

Bob
maspegren 21 Jan, 2014
This worked great for the To field, but when I do the same thing for a variable I would like in the email body, it didn't work. It is the exact same method as above, but different code:
$query = "SELECT instructor FROM options WHERE location = '{$form->data['choose_location_dropdown']}' AND CONCAT(date,' ',time,' ',vehicle) = '{$form->data['choose_date_dropdown']}';";
$db->setQuery($query);
$the_instructor = $db->loadResult();
$form->data['the_instructor'] = $instructor;


Then I put {instructor} in the email body, and the email still shows {instructor}. I verified the SQL statement returns a value. Just to check, I also replaced the SQL statement with a basic statement that returns one value, this didn't work either. Is the syntax different if I want to put a value in the email body? I looked through the Help for the Email[GH] action and didn't find anything about it.
maspegren 21 Jan, 2014
Nevermind, I must have missed something somewhere. I rewrote the section of code and it is working correctly now. Thank you for your attention!
GreyHead 21 Jan, 2014
HI Maspegren,

The code you posted had $the_instructor in one line and $instructor in the next one.

Bob
maspegren 21 Jan, 2014
I bet you're right! For some reason I had in mind that the variable holding the result had to be the same as the new variable, and the variable to the right of the last line should be different. My successful test was when I named all three the same! Thank you! I think I was just staring at it too long... Hope this helps someone🙂
This topic is locked and no more replies can be posted.