public static function formRule($params, $files, $self) {
$errors = array();
- //empty file upload validation for odt/docx template
- if (empty($files['file_id']['tmp_name']) && !empty($params['file_type']) && !$self->_is_document) {
+ // If user uploads non-document file other than odt/docx
+ if (!empty($files['file_id']['tmp_name']) &&
+ array_search($files['file_id']['type'], CRM_Core_SelectValues::documentApplicationType()) == NULL
+ ) {
+ $error['file_id'] = ts('Invalid document file format');
+ }
+ // If default is not set and no document file is uploaded
+ elseif (empty($files['file_id']['tmp_name']) && !empty($params['file_type']) && !$self->_is_document) {
//On edit page of docx/odt message template if user changes file type but forgot to upload document
$errors['file_id'] = ts('Please upload document');
}
*
* @param array $fields
* The input form values.
- * @param array $dontCare
+ * @param array $files
* @param array $self
* Additional values form 'this'.
*
* @return bool
* TRUE if no errors, else array of errors.
*/
- public static function formRule($fields, $dontCare, $self) {
+ public static function formRule($fields, $files, $self) {
$errors = array();
$template = CRM_Core_Smarty::singleton();
+ // If user uploads non-document file other than odt/docx
+ if (empty($fields['template']) &&
+ !empty($files['document_file']['tmp_name']) &&
+ array_search($files['document_file']['type'], CRM_Core_SelectValues::documentApplicationType()) == NULL
+ ) {
+ $errors['document_file'] = ts('Invalid document file format');
+ }
//Added for CRM-1393
if (!empty($fields['saveTemplate']) && empty($fields['saveTemplateName'])) {
$errors['saveTemplateName'] = ts("Enter name to save message template");
mimeType = $('a.delete-attachment').data('mimetype');
}
- showHideUpload($("input[id$='_file_type']").val());
+ var selector = $("input[id$='_file_type']").attr('type') == 'radio' ? "input[id$='_file_type']:checked" : "input[id$='_file_type']";
+ showHideUpload($(selector).val());
$("input[id$='_file_type']").on('click', function(){
showHideUpload(this.value);
});