add second attachment field

This commit is contained in:
Nathan Coad
2018-06-26 18:04:38 +10:00
parent 01b0b05428
commit 598b6f653f

View File

@@ -129,10 +129,23 @@ function booking_manual_email_form($form, &$form_state)
'wrapper' => 'booking_email_default_ids_wrapper', 'wrapper' => 'booking_email_default_ids_wrapper',
), ),
); );
$form['booking-email-preview'] = array(
'#type' => 'container',
'#children' => "<h3>Email Preview</h3><pre>No email type selected.</pre>",
'#prefix' => '<div id="booking_email_preview_wrapper">',
'#suffix' => '</div>',
);
$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', '#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')), '#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_location' => 'public://bookings/emails',
'#upload_validators' => array( '#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')), '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 // 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' => "<h3>Email Preview</h3><pre>No email type selected.</pre>",
'#prefix' => '<div id="booking_email_preview_wrapper">',
'#suffix' => '</div>',
);
$form['submit'] = array ( $form['submit'] = array (
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Send Email'), '#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', '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))); //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) { // Add attachments if present
$attachments[] = file_load($form_state['values']['booking-email-attachment']); if (isset($form_state['values']['booking-email-attachment-1']) && $form_state['values']['booking-email-attachment-1'] != 0) {
watchdog('booking_debug', 'File attachment detected: @info', array ('@info' => print_r($attachment, TRUE))); $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 // 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 // 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) { foreach($checkboxes as $key => $value) {
//do a sanity check on the key => value pair from the form submission //do a sanity check on the key => value pair from the form submission