From 00862913d8213e401b47d6ed126d4c011e82acce Mon Sep 17 00:00:00 2001 From: dolibarr95 Date: Wed, 27 Sep 2017 11:12:38 +0200 Subject: [PATCH] Add the attribute accept to input tag I know this is not a security check but it is more convenient for the user when in a form only images or pdf are accepted for example. see : *https://www.w3.org/wiki/HTML/Elements/input/file *https://www.w3schools.com/TagS/att_input_accept.asp Hope every body needs it. tks --- htdocs/core/class/html.formfile.class.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 9d01a3c70b2..73198771b93 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -57,21 +57,22 @@ class FormFile /** * Show form to upload a new file * - * @param string $url Url - * @param string $title Title zone (Title or '' or 'none') + * @param string $url Url + * @param string $title Title zone (Title or '' or 'none') * @param int $addcancel 1=Add 'Cancel' button * @param int $sectionid If upload must be done inside a particular ECM section * @param int $perm Value of permission to allow upload - * @param int $size Length of input file area. Deprecated. - * @param Object $object Object to use (when attachment is done on an element) - * @param string $options Add an option column - * @param integer $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used. - * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__' - * @param integer $linkfiles 1=Also add form to link files, 0=Do not show form to link files - * @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM) + * @param int $size Length of input file area. Deprecated. + * @param Object $object Object to use (when attachment is done on an element) + * @param string $options Add an option column + * @param integer $useajax Use fileupload ajax (0=never, 1=if enabled, 2=always whatever is option). 2 should never be used. + * @param string $savingdocmask Mask to use to define output filename. For example 'XXXXX-__YYYYMMDD__-__file__' + * @param integer $linkfiles 1=Also add form to link files, 0=Do not show form to link files + * @param string $htmlname Name and id of HTML form ('formuserfile' by default, 'formuserfileecm' when used to upload a file in ECM) + * @param string $accept Specifies the types of files accepted (This is not a security check but an user interface facility. eg '.pdf,image/*' or '.png,.jpg' or 'video/*') * @return int <0 if KO, >0 if OK */ - function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile') + function form_attach_new_file($url, $title='', $addcancel=0, $sectionid=0, $perm=1, $size=50, $object='', $options='', $useajax=1, $savingdocmask='', $linkfiles=1, $htmlname='formuserfile', $accept='') { global $conf,$langs, $hookmanager; $hookmanager->initHooks(array('formfile')); @@ -130,6 +131,7 @@ class FormFile $out .= 'global->MAIN_DISABLE_MULTIPLE_FILEUPLOAD) || $conf->browser->layout != 'classic')?' name="userfile"':' name="userfile[]" multiple'); $out .= (empty($conf->global->MAIN_UPLOAD_DOC) || empty($perm)?' disabled':''); + $out .= (!empty($accept)?' accept="'.$accept.'"':'accept=""'); $out .= '>'; $out .= ' '; $out .= '