PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Notification Attachments for Multiple Forms

  1. Suzanne
    Member

    I have a client who, for his own reasons, wants multiple forms, each one sending a different document to the user who provides and email address. I found the gform_user_notification_attachments action and got that to work just fine for ALL form submissions, but obviously in this case, I need to send a different document depending on which form was submitted. So I modified the suggested code to switch the form ID - far more efficient and tidy than any other way - but for some reason it's not sending the document.

    I do get the user notification. Yes. If I hard code one of the documents on the line that reads $attachments[] = $upload_path . $doc; for example, $attachments[] = $upload_path . "doc1.pdf"; then yes I will get that document, but as it stands below, it's not working. The only thing I can think of is that $form is in a format other than simple ID numbers?

    add_filter("gform_user_notification_attachments", "add_attachment", 10, 3);
    function add_attachment($attachments, $lead, $form) {
    
        switch($form) {
          case "1":
            $doc = "/2012/08/document_1_for_form_1.pdf";
            break;
          case "2":
            $doc = "/2012/08/document_2_for_form_2.pdf";
            break;
        }
    
        $upload = wp_upload_dir();
        $upload_path = $upload["basedir"];
    
        $attachments = array();
        $attachments[] = $upload_path . $doc;
    
        return $attachments;
    
    }

    When I switch the form ID, am I doing that right? I'm assuming that the function is receiving the form ID in the variable $form but maybe I've got the data format wrong?

    Any help getting this working would be great. Thanks

    Posted 11 years ago on Wednesday August 22, 2012 | Permalink
  2. David Peralty

    Have you tried it without the quotation marks around the switch numbers?

    Posted 11 years ago on Wednesday August 22, 2012 | Permalink
  3. Suzanne
    Member

    Hi David, yes I originally had it set up without quotes but that didn't even send the email. I tried all three scenarios: no quotes, single quotes and double quotes. This was the result for each:

    • no quotes = no email

    • single quotes = no email

    • double quotes = email but no attachment

    Posted 11 years ago on Wednesday August 22, 2012 | Permalink
  4. Suzanne
    Member

    I also just tried an if/elseif/else scenario and it fails as well... I get the emails, but no attachments. Hard-code the document to the $attachments[]= line and I get the email AND attachment so the problem is occurring when attempting to handle the $form value. Do you know exactly how that value is being passed? or if it even is? I'm half inclined to believe we're getting an empty variable there.

    add_filter("gform_user_notification_attachments", "add_attachment", 10, 3);
    function add_attachment($attachments, $lead, $form) {
    
        if($form==1) {
            $doc = '/2012/08/doc1.pdf';
        } elseif($form==2) {
            $doc = '/2012/08/doc2.pdf';
        } elseif($form==3) {
            $doc = '/2012/08/doc3.pdf';
        } else {
          $doc = '';
        }
    
        $upload = wp_upload_dir();
        $upload_path = $upload["basedir"];
    
        $attachments = array();
        $attachments[] = $upload_path . $doc;
    
        return $attachments;
    
    }
    Posted 11 years ago on Wednesday August 22, 2012 | Permalink
  5. Suzanne
    Member

    Okay... I solved this... the problem *is* with the $form variable. It's not actually passing a literal form ID. It's passing an array. Either of my solutions above will work (for those interested) but instead of using $form in your comparison operations, you have to use $form['id'] like this:

    if ( $form[ 'id' ] == 1 ) {
      $doc = '/2012/08/doc1.pdf';
    }
    Posted 11 years ago on Wednesday August 22, 2012 | Permalink
  6. Nice, thanks for the update - glad you got it working!

    Posted 11 years ago on Thursday August 23, 2012 | Permalink

This topic has been resolved and has been closed to new replies.