I am working on a system that creates a pdf bill from information from an eform
the pdf is created now and that works nice using the events. now I like to attach this pdf to the mail.
Not out of the box. What you would need to do is to add the file location to the $attachments array. $attachments is being populated from the $_FILES array during form validation but only if it finds a form field (in the fields array ) with the type set to "file".
I’m afraid this is not possible without hacking eForm itself. I would extend the
eFormOnBeforeMailSent. Search for the following code
//<?php
# invoke OnBeforeMailSent event set by another script
if ($eFormOnBeforeMailSent) {
if( $isDebug && !function_exists($eFormOnBeforeMailSent))
$fields['debug'] .= "eFormOnBeforeMailSent event: Could not find the function " . $eFormOnBeforeMailSent;
elseif ($eFormOnBeforeMailSent($fields)===false) {
if( isset($fields['validationmessage']) && !empty($fields['validationmessage']) ){
//register css and/or javascript
if( isset($startupSource) ) efRegisterStartupBlock($startupSource);
return formMerge($tpl,$fields);
}
else
return;
}
}
//?>
And replace this line:
//<?php
elseif ($eFormOnBeforeMailSent($fields)===false) {
with
//<?php
elseif ($eFormOnBeforeMailSent($fields,$attachments)===false) {
Now also change your function for this event to accept this extra argument. Note the
&. The arguments should be declared as reference!
//<?php
//example function
function onBeforeMailSentFunction( &$fields, &$attachments){
//add extra file to attachments
if( file_exists("/path/to/extra_file.pdf") ) {
$attachments[] = "/path/to/extra_file.pdf";
}
return true;
}
also the &eFormOnBeforeMailSent is triggered before the validation. is there another event that is after validation but before mail is send?
What makes you say that? The
eFormOnBeforeMailSent event is triggered after the form validates. If eForm notices a form error it never fires. At least it shouldn’t. By the way the
eFormOnValidate event happens after successful validation and before
eFormOnBeforeMailSent