Forums

Send an email with a PDF attached when connection action is present...

arrick 03 Apr, 2015
Ok... So, I know that the following works with my original form...

FORM NAME: DVOPApplicationForm
Step 1: Field which has a field name of "recipients".
Step 2: Custom Code entry as first item in "On Submit"

<?php
/*Staff Email Selection*/
if ( isset($form->data['recipients']) && $form->data['recipients'] ) {
  $recipient = $form->data['recipients'];
}
$emails = array (
  'Muskegon' => 'email@domain.org',
  'Oceana' => 'email@domain.org',
  'Ottawa' => 'email@domain.org' );
$form->data['email_to_use'] = $emails[$recipient];
?>

Step 3: TCPDF action which produces a PDF exactly how I want it.
Step 4: Email, with dynamic email address, with the "Dynamic To" field set to "email_to_use"
Step 5: Fill out form, hit submit, it works as expected.


In my other form, which is for updating the DB table that the original information is pulled from, form, I currently have the following:

FORM NAME: DVOPApplicationFormMWStaffReferral
Step 1: Field which has a field name of "dvopid[DVOPSReferredTo]". (dvopid is the model id for matching a record to data)
Step 2: Custom Code entry as first item in "On Submit"

<?php
/* */
/* DVOPS Selection */
if ( isset($form->data['dvopid']['DVOPSReferredTo']) && $form->data['dvopid']['DVOPSReferredTo'] ) {
  $['dvopid']['DVOPSReferredTo'] = $form->data['dvopid']['DVOPSReferredTo'];
}
$emails = array (
  'Kelly Berger' => 'email@domain.org' );
$form->data['dvop_selected'] = $emails[$dvopid][$DVOPSReferredTo];
/* */
?>

Step 3: Email action, with dynamic email address, with the "Dynamic To" field set to "dvop_selected"
Step 4: Submit the form, and I get an error which says:
•Mailer Error: You must provide at least one recipient email address.

I believe my error is located at the last line which contains below, but I am not sure what that line should look like... if it is elsewhere, please correct me... I am definitely learning php with this....
$form->data['dvop_selected'] = $emails[$dvopid][$DVOPSReferredTo];
arrick 03 Apr, 2015
I have put a debugger into the system, and removed the connection action, added a db save temporarily to troubleshoot.... the result is below.

Array
(
    [23] => Array
        (
            [TCPDF] => Array
                (
                    [0] => E:\formsite\components\com_chronoforms5\chronoforms\pdfs\DVOPApplicationFormMWStaffReferral\DVOPApplicationForm_20150403110116.pdf has been saved correctly.
                )

        )

    [21] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below could NOT be sent:
                    [1] => To:
                    [2] => Subject:DVOP Referral
                    [3] => From name:MW Staff
                    [4] => From email:noreply@miworksmo.org
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Array
                        (
                            [0] => E:\formsite\components\com_chronoforms5\chronoforms\pdfs\DVOPApplicationFormMWStaffReferral\DVOPApplicationForm_20150403110116.pdf
                        )

                    [11] => Body:
Good Day,
<br /><br />
  has submitted an application for DVOP Services on: ?>.<br/>
<br />
At this time   is  for services.
<br />
<br />
Thank You,<br />
Michigan Works! Staff.
<br /><br />IP: 10.10.20.46
                )

        )

)
arrick 03 Apr, 2015
Disregard, the answer was simpler than I thought... It is now resolved.
arrick 03 Apr, 2015
Answer
For those that need help with this in the future, the answer laid in the custom php syntax, Below is the solution.

<?php
/* */
/* DVOP Selection */
if ( isset($form->data['dvopid']['DVOPSReferredTo']) && $form->data['dvopid']['DVOPSReferredTo'] ) {
  $referredTo = $form->data['dvopid']['DVOPSReferredTo'];
}
$emails = array (
  'Kelly Berger' => 'moorear@miworksmo.org' );
$form->data['dvop_selected'] = $emails[$referredTo];
/* */

?>
GreyHead 04 Apr, 2015
1 Likes
Hi Moorear,

Hmmm . . . the purpose of the first part of the code is to set a default value if nothing is submitted from the form. I don't think that your code does that. And you may not need it if the validation is robust.

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