diff --git a/main/document/create_document.php b/main/document/create_document.php index cc55013fa4..6aad14d8b4 100644 --- a/main/document/create_document.php +++ b/main/document/create_document.php @@ -1,10 +1,10 @@ defaultRenderer(); //$filename_template = str_replace('{element}', "$display_dir {element} .html", $renderer->_elementTemplate); $filename_template = str_replace('{element}', "{element}", $renderer->_elementTemplate); $renderer->setElementTemplate($filename_template, 'filename'); + +// initialize group array +$group = array(); + // If allowed, add element for document title if (api_get_setting('use_document_title') == 'true') -{ - $form->add_textfield('title', get_lang('Title'),true,'class="input_titles" id="title"'); +{ + //$group[]= $form->add_textfield('title', get_lang('Title'),true,'class="input_titles" id="title"'); + // replace the add_textfield with this + $group[]=$form->createElement('text','title',get_lang('Title'),'class="input_titles" id="title"'); + //$form->applyFilter('title','trim'); + //$form->addRule('title', get_lang('ThisFieldIsRequired'), 'required'); } else -{ - $form->add_textfield('filename', get_lang('FileName'),true,'class="input_titles" id="filename" onblur="check_if_still_empty()"'); - $form->addRule('filename', get_lang('FileExists'), 'callback', 'document_exists'); +{ + //$form->add_textfield('filename', get_lang('FileName'),true,'class="input_titles" id="filename" onblur="check_if_still_empty()"'); + // replace the add_textfield with this + $group[]=$form->createElement('text','filename',get_lang('FileName'),'class="input_titles" id="filename" onblur="check_if_still_empty()"'); + //$form->applyFilter('filename','trim'); + //$form->addRule('filename', get_lang('ThisFieldIsRequired'), 'required'); + //$form->addRule('filename', get_lang('FileExists'), 'callback', 'document_exists'); } -$renderer->setElementTemplate('
{element}{label}
', 'readonly'); -$form->addElement('checkbox','readonly',get_lang('ReadOnly')); +//$renderer->setElementTemplate('
{element}{label}
', 'readonly'); +$group[]= $form->createElement('checkbox','readonly','',get_lang('ReadOnly')); + +// add group to the form +$form->addGroup($group, 'filename_group', get_lang('FileName') ,'   ', false); +$form->addRule('filename_group', get_lang('ThisFieldIsRequired'), 'required'); + +if (api_get_setting('use_document_title') == 'true') +{ + $form->addGroupRule('filename_group', array( + 'title' => array( + array(get_lang('ThisFieldIsRequired'), 'required'), + array(get_lang('FileExists'),'callback', 'document_exists') + ) + )); +} +else +{ + $form->addGroupRule('filename_group', array( + 'filename' => array( + array(get_lang('ThisFieldIsRequired'), 'required'), + array(get_lang('FileExists'),'callback', 'document_exists') + ) + )); +} $form->addElement('submit', 'submit', get_lang('Ok')); @@ -288,6 +325,9 @@ if ($form->validate()) { $values = $form->exportValues(); $readonly = isset($values['readonly']) ? 1 : 0; + $values['title']=trim($values['title']); + $values['filename']=trim($values['filename']); + if (api_get_setting('use_document_title') != 'true') { $values['title'] = $values['filename']; @@ -296,6 +336,7 @@ if ($form->validate()) { $values['filename'] = $values['title']; } + $filename = replace_accents($values['filename']); $texte = $values['content']; $title = $values['filename'];