From 598b6f653f09c327ba945feb33afd862a991ca48 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Tue, 26 Jun 2018 18:04:38 +1000 Subject: [PATCH] add second attachment field --- booking.email_manually.inc | 46 ++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/booking.email_manually.inc b/booking.email_manually.inc index ae82c73..3781bc7 100644 --- a/booking.email_manually.inc +++ b/booking.email_manually.inc @@ -129,10 +129,23 @@ function booking_manual_email_form($form, &$form_state) 'wrapper' => 'booking_email_default_ids_wrapper', ), ); + + $form['booking-email-preview'] = array( + '#type' => 'container', + '#children' => "

Email Preview

No email type selected.
", + '#prefix' => '
', + '#suffix' => '
', + ); - $form['booking-email-attachment'] = array( + $form['attachments'] = array( + '#type' => 'fieldset', + '#title' => 'Attach Files', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['attachments']['booking-email-attachment-1'] = array( '#type' => 'managed_file', - '#title' => t('Email attachment'), + '#title' => t('Email attachment 1'), '#description' => t('Attach a file to be emailed. Note that this only works with custom email types. File must be 10MB or less, and extension must be one of: ' . variable_get('booking_email_allowed_attachments', 'pdf docx')), '#upload_location' => 'public://bookings/emails', '#upload_validators' => array( @@ -140,6 +153,16 @@ function booking_manual_email_form($form, &$form_state) 'file_validate_extensions' => array(variable_get('booking_email_allowed_attachments', 'pdf docx')), ), ); + $form['attachments']['booking-email-attachment-2'] = array( + '#type' => 'managed_file', + '#title' => t('Email attachment 2'), + '#description' => t('Attach a file to be emailed. Note that this only works with custom email types. File must be 10MB or less, and extension must be one of: ' . variable_get('booking_email_allowed_attachments', 'pdf docx')), + '#upload_location' => 'public://bookings/emails', + '#upload_validators' => array( + 'file_validate_size' => array(10*1024*1024), + 'file_validate_extensions' => array(variable_get('booking_email_allowed_attachments', 'pdf docx')), + ), + ); /* // See https://drupal.stackexchange.com/questions/108583/how-to-save-file-uploaded-with-plupload-integration-module-and-make-it-managed @@ -184,13 +207,7 @@ function booking_manual_email_form($form, &$form_state) ); */ - $form['booking-email-preview'] = array( - '#type' => 'container', - '#children' => "

Email Preview

No email type selected.
", - '#prefix' => '
', - '#suffix' => '
', - ); - + $form['submit'] = array ( '#type' => 'submit', '#value' => t('Send Email'), @@ -474,12 +491,17 @@ function booking_manual_email_form_submit($form, &$form_state) { //watchdog('booking', 'Formstate when setting buttons: @info', array ('@info' => var_export($form_state['values'], TRUE))); //watchdog('booking', 'Checkboxes when setting buttons: @info', array ('@info' => var_export($checkboxes, TRUE))); - if (isset($form_state['values']['booking-email-attachment']) && $form_state['values']['booking-email-attachment'] != 0) { - $attachments[] = file_load($form_state['values']['booking-email-attachment']); - watchdog('booking_debug', 'File attachment detected: @info', array ('@info' => print_r($attachment, TRUE))); + // Add attachments if present + if (isset($form_state['values']['booking-email-attachment-1']) && $form_state['values']['booking-email-attachment-1'] != 0) { + $attachments[] = file_load($form_state['values']['booking-email-attachment-1']); + watchdog('booking_debug', 'File attachment 1 detected: @info', array ('@info' => print_r($attachments, TRUE))); // NOTE: Since we do nothing to save this file, it should get cleaned up by cron // As per https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7.x#managed_file } + if (isset($form_state['values']['booking-email-attachment-2']) && $form_state['values']['booking-email-attachment-2'] != 0) { + $attachments[] = file_load($form_state['values']['booking-email-attachment-2']); + watchdog('booking_debug', 'File attachment 2 detected: @info', array ('@info' => print_r($attachments, TRUE))); + } foreach($checkboxes as $key => $value) { //do a sanity check on the key => value pair from the form submission