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