Hi Shaun,
thanks for this great snippet, I’m getting more and more into it and I love it =)...I recently had the need to disable the FileAttachment in email (I did a cURL FTP Upload Snippet btw. Hook, would like to contribute if you could package the whole thing, I have no idea how the transport.package thing works...), this was possible with a new FormIt snippet property I made, it’s called "emailAttachment=`boolean`" and I also had to change some lines in the fihook.class.php file:
/* handle file fields */
foreach ($fields as $k => $v) {
//xodmod: make it possible to disable email attachments
$attachment = (boolean)$this->modx->getOption('emailAttachment',$this->formit->config,true);
if ($attachment === true) {
if (is_array($v) && !empty($v['tmp_name']) && isset($v['error']) && $v['error'] == UPLOAD_ERR_OK) {
$this->modx->mail->mailer->AddAttachment($v['tmp_name'],$v['name'],'base64',!empty($v['type']) ? $v['type'] : 'application/octet-stream');
}
}
}
maybe you want to improve the code or take it in the next release...?
keep up your good work!
EDIT1: The above code didn’t work as expected...I have had this problem multiple times with Snippets,
how can I pass booleans as booleans??? When I typecast the thing like above I always get a "1" = true, no matter what is really set... when I change it to a "string-construction" it works...but this is ugly/unclean/unprofessional =/
/* handle file fields */
foreach ($fields as $k => $v) {
//xodmod: make it possible to disable email attachments
$attachment = $this->modx->getOption('emailAttachment',$this->formit->config,'true');
if ($attachment === 'true') {
if (is_array($v) && !empty($v['tmp_name']) && isset($v['error']) && $v['error'] == UPLOAD_ERR_OK) {
$this->modx->mail->mailer->AddAttachment($v['tmp_name'],$v['name'],'base64',!empty($v['type']) ? $v['type'] : 'application/octet-stream');
}
}
}
EDIT2: I also recognized a repeatedly occuring error:
ERROR @ /home/exodch/public_html/bern-derfilm/core/components/formit/model/formit/fivalidator.class.php : 104) PHP warning: Illegal offset type in isset or empty
it’s the line:
/* handle checkboxes/radios with empty hiddens before that are field[] names */
if (is_array($v) && !isset($_FILES[$v]) && empty($v[0])) array_splice($v,0,1);
any idea why this is?