This helped me to create a confrmation mail for the submitter:
http://cipalabs.com/modx/articles/send-a-confirmation-email-with-formit
But I'm still struggling with radiobuttons and getting their value included into the confirmation-mail!
This is my FormIt-Call
[[!FormIt?
&customValidators=`Check-Name,Check-Email,Telefon`
&store=`1`
&hooks=`spam,email,customhook,redirect`
&emailTpl=`mail-chunk`
&emailTo=`[email protected]`
&emailFromName=`[[+name]]`
&emailSubject=`Neue Kurs-Anmeldungen`
&redirectTo=`3`
&validate=`name:Check-Name:required,
telefon:Check-Telefon:required,
email:Check-Email:required,
colors:required`]]
This is my html-form:
<form action="[[~[[*id]]]]" method="post" class="form">
<input type="hidden" name="colors" value="[[+fi.colors]]" />
<ul>
<li>
<input type="checkbox" name="colors[]" value="Kurs1 ########" />
</li>
<li>
<input type="checkbox" name="colors[]" value="Kurs2 ########" />
</li>
<li>
<input type="checkbox" name="colors[]" value="Kurs3 ########" />
</li>
</ul>
<div class="clear"> </div>
<input type="text" name="name" id="name" value="[[!+fi.name:empty=`Dein Name`]]" [[!+fi.error.name:notempty=`class="error"`]] onfocus="this.value='';" onblur="if (this.value=='') this.value='Dein Name';" /><br />
<input type="text" name="telefon" id="telefon" value="[[!+fi.telefon:empty=`Deine Telefonnummer`]]" [[!+fi.error.telefon:notempty=`class="error"`]] onfocus="this.value='';" onblur="if (this.value=='') this.value='Deine Telefonnummer';" /><br />
<input type="text" name="email" id="email" value="[[!+fi.email:empty=`Deine Email-Adresse`]]" [[!+fi.error.email:notempty=`class="error"`]] onfocus="this.value='';" onblur="if (this.value=='') this.value='Deine Email-Adresse';" /><br class="clear" />
<div class="form-buttons">
<input type="submit" value="> FÜR AUSGEWÄHLTE KURSE ANMELDEN" />
</div>
</form>
This is the normal mail-chunk send to the admin:
Name: [[+name]]<br />
Email: [[+email]]<br /><br />
Die Anmeldung erfolgt für folgende Kurse:<br /><br />
[[+colors]]
By using this the values of the selected checkboxes get transmitted by the placeholder [[+colors]], when all checkboxes got checked and the form submitted -
nearly like i want it to be; i only don't know how i separate each value with a linebreak instead of the "########" i added?
This is how the placeholder [[+colors]] get transmitted in the mail-chunk:
Kurs1 ######## Kurs2 ######## Kurs3 ########
I want these values separated by a linebreak or inside a html-list...
But my bigger problem is when I use this for the Confirmation-Mail-Tpl, the "placeholder" [[+colors]] is empty, regardless how many checkboxes have been checked before:
Hallo [[+name]]!<br /><br />
Wir haben Deine Kurs-Anmeldungen erhalten.<br /><br />
Email: [[+email]]<br /><br />
Die Anmeldung erfolgt für folgende Kurse:<br /><br />
[[+colors]]
Here is the customhook-snippet:
<?php
//configuration
$mailFrom = $modx->getOption('emailsender'); //OR USE YOUR OWN;
$mailFromName = $modx->getOption('site_name'); //OR USE YOUR OWN;
$mailSender = $modx->getOption('site_name'); //OR USE YOUR OWN;
$mailSubject = 'MY SUBJECT';
$mailReplyTo = $mailFrom;
//get fields values so they can be replaced in the email chunk
$confirmationFields['name'] = $scriptProperties['fields']['name'];
$confirmationFields['email'] = $scriptProperties['fields']['email'];
$confirmationFields['colors'] = $scriptProperties['fields']['colors'];
//get user's email
$mailTo= $scriptProperties['fields']['email'];
$text = $modx->getChunk('ConfirmationTpl', $confirmationFields);
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$text);
$modx->mail->set(modMail::MAIL_FROM,$mailFrom);
$modx->mail->set(modMail::MAIL_FROM_NAME,$mailFromName);
$modx->mail->set(modMail::MAIL_SENDER,$mailSender);
$modx->mail->set(modMail::MAIL_SUBJECT,$mailSubject);
$modx->mail->address('to',$mailTo);
$modx->mail->address('reply-to',$mailReplyTo);
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
$modx->mail->reset();
return true;
}
$modx->mail->reset();
return true;
Additional info to the customhook-snippet:
I had to edit this original part:
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
}
to this
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$err);
$modx->mail->reset();
return true;
}
because otherwise the form doesn't redirect on submit. There's somewhere an error inside this if-condition i couldn't sort out. But as the mails get sent I chose this "workaround" to get the redirection-hook running as desired...
So can anybody tell me how i get a linebreak for each [[+colors]]-placeholder? And how do i get this placeholder filled and the values transmitted in the Confirmation-Mail too?