fix attachment validators

This commit is contained in:
Nathan Coad
2018-06-16 20:22:49 +10:00
parent 08e9d220d6
commit 6f971767f0

View File

@@ -129,9 +129,12 @@ function booking_manual_email_form($form, &$form_state)
$form['booking-email-attachment'] = array( $form['booking-email-attachment'] = array(
'#type' => 'managed_file', '#type' => 'managed_file',
'#title' => t('Email attachment'), '#title' => t('Email attachment'),
'#description' => t('Attach a file to be emailed. Note that this only works with custom email types. File 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(variable_get('booking_email_allowed_attachments', 'pdf docx')), '#upload_validators' => array(
'file_validate_size' => array(10*1024*1024),
'file_validate_extensions' => array(variable_get('booking_email_allowed_attachments', 'pdf docx')),
),
); );
$form['booking-email-preview'] = array( $form['booking-email-preview'] = array(
@@ -412,31 +415,6 @@ function _booking_email_get_default_selection_callback($form, $form_state) {
); );
} }
/**
* Function to handle sending the manual emails
*/
/*
function booking_manual_email_from_validation($form, &$form_state) {
$file = file_save_upload('file', array(
'file_validate_extensions' => array(variable_get('booking_email_allowed_attachments', 'pdf docx')), // Validate extensions.
));
// If the file passed validation:
if ($file) {
// Move the file, into the Drupal file system
if ($file = file_move($file, 'public://', FILE_EXISTS_REPLACE )) {
// Save the file for use in the submit handler.
$form_state['storage']['file'] = $file;
}
else {
form_set_error('file', t('Failed to write the uploaded file to the site\'s file folder.'));
}
}
else {
form_set_error('file', t('No file was uploaded.'));
}
}
*/
/** /**
* Function to handle sending the manual emails * Function to handle sending the manual emails
*/ */
@@ -452,6 +430,8 @@ function booking_manual_email_form_submit($form, &$form_state) {
if (isset($form_state['values']['booking-email-attachment'])) { if (isset($form_state['values']['booking-email-attachment'])) {
$attachment = file_load($form_state['values']['booking-email-attachment']); $attachment = file_load($form_state['values']['booking-email-attachment']);
watchdog('booking_debug', 'File attachment detected: @info', array ('@info' => print_r($attachment, TRUE))); watchdog('booking_debug', 'File attachment detected: @info', array ('@info' => print_r($attachment, 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
} }
foreach($checkboxes as $key => $value) { foreach($checkboxes as $key => $value) {