Answer the question
In order to leave comments, you need to log in
How to add custom placeholder to FormIt hook?
The site has a form with ordering price lists. They are taken from a directory in the site directory.
I iterate and generate links like this:
$dir = 'prices';
if ( $handle = opendir( $dir ) )
{
while ( $file = readdir($handle) )
{
for ($i=0; $i<count($file); $i++)
if(($file != '.') && ($file != '..') && ($file[0] != '.')) {
$file = mb_convert_encoding($file, "utf-8", "windows-1251");
$file = '<br /><a href="https://.../prices/'.$file.'">'.$file.'</a>';
$fileOrder[] = $file;
}
};
closedir( $handle );
};
<?php
$fields = $hook->getValues();
$message = $modx->getChunk('tpl.mail.price', $fields);
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY, $message);
$modx->mail->set(modMail::MAIL_FROM, $modx->getOption('emailsender'));
$modx->mail->set(modMail::MAIL_FROM_NAME, $modx->getOption('site_name'));
$modx->mail->set(modMail::MAIL_SUBJECT, 'Прайс-лист');
$modx->mail->address('to', $fields['email']);
$modx->mail->address('reply-to', $modx->getOption('emailsender'));
$modx->mail->setHTML(true);
$dir = 'prices';
if ( $handle = opendir( $dir ) )
{
while ( $file = readdir($handle) )
{
for ($i=0; $i<count($file); $i++)
if(($file != '.') && ($file != '..') && ($file[0] != '.')) {
$file = mb_convert_encoding($file, "utf-8", "windows-1251");
$file = '<br /><a href="https://.../prices/'.$file.'">'.$file.'</a>';
$fileOrder[] = $file;
}
};
closedir( $handle );
};
$hook->setValue('fileOrder', $fileOrder);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
$modx->mail->reset();
return true;
`
Answer the question
In order to leave comments, you need to log in
Let me summarize again. The hook doesn't need to pass anything extra. Set the desired value ($fields['fileOrder'] = implode(",", $fileOrder)) in the parameters array for getChunk, is there definitely something in $fileOrder?
First the $fields['fileOrder'] value, then passing the $fields parameter array to getChunk.
Well, this is an array, so we need some kind of readable form in the body of the letter .. wrap it in something (yes, at least in implode). And for simplicity, you can first pass the text and make sure that it appears in the body of the letter under the placeholder.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question