Add allowed file extensions in Views Send file field Using the Views Send module to send mass email.
On the email creation page I want to set my custom validation extensions for the file field provided by Views Send in combination with MimeMail (r# 267 in views_send.module).

For the file field I am trying to set the only allowed extension to be of type .docx by using the following function:

function my_module_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if($form_id == "views_form_views_send_page") {
    if ($form_state['step'] == 'views_send_config_form') {

      $form['mail']['views_send_attachments'] = array(
        '#type' =&gt; 'file',
        '#title' =&gt; t('Attachment'),
        '#upload_validators' =&gt; array(
          'file_validate_extensions' =&gt; array('docx'),
        ),
     );
  }
}


Unfortuanetely this is not working. What am I doing wrong here?
Turns out the file behavior you're looking for is not defined for file elements, but for managed_files. It's as easy as:

/**
 * Implements hook_form_FORM_ID_alter().
 */
function my_module_form_views_form_send_page_alter(&amp;$form, &amp;$form_state) {
  if ($form_state['step'] == 'views_send_config_form') {
    $form['mail']['views_send_attachments']['#type'] = 'managed_file';
    $form['mail']['views_send_attachments']['#upload_validators']['file_validate_extensions'][] = 'docx';
  }
}


But views_send will have to be patched to support managed_files. This still needs work in the issue queue.



Yet, as I mention in the issue, you can hack it directly in the module. It's not recommended, but we don't have a hook here and the issue above might take a while to be solved. So just change the line

$file = file_save_upload('views_send_attachments', array(), $dir);


to

$file = file_save_upload('views_send_attachments', array('file_validate_extensions' =&gt; array('docx')), $dir);