We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    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.

    Is this possible?
    I tried to put some info in the $_FILES array but that did not work.
    but maybe I do it wrong.

    if this works than my project is almost finished.
    also the &eFormOnBeforeMailSent is triggered before the validation. is there another event that is after validation but before mail is send?
    i noticed that when an validation error acured (like no good mailadres) that the &eFormOnBeforeMailSent is triggered that is not good that way the data is already in the database in my case and I get double entry’s for one user.

    Dimmy
      follow me on twitter: @dimmy01
      • 30223
      • 1,010 Posts
      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
        • 7455
        • 2,204 Posts
        Thank your for this fix, makes eform even more flexible.


        mm now I am not shure what I do know for sure is that the event is triggered when pressed f5 (refresh) and the error message on screen say’s you already submitted this form successfully (something like that) this message should in my opinion be showen before the beformailsend event it will cause my pdf to be sent more then once if someone presses f5.

        I will test the other case if the event is triggered on error.

        Dimmy
          follow me on twitter: @dimmy01