function form_copyselection() { $oForm = new KTForm(); $oForm->setOptions(array('label' => _kt('Copy Document'), 'submit_label' => _kt('Copy'), 'identifier' => 'ktcore.actions.copydoc', 'action' => 'copy', 'cancel_url' => KTBrowseUtil::getUrlForDocument($this->oDocument), 'fail_action' => 'main', 'context' => $this)); /* * This is somewhat more complex than most forms, since the "filename" * and title shouldn't appear unless there's a clash. * * This is still not the most elegant solution. */ $widgets = array(); $widgets[] = array('ktcore.widgets.foldercollection', array('label' => _kt('Target Folder'), 'description' => _kt('Use the folder collection and path below to browse to the folder you wish to copy the documents into.'), 'required' => true, 'name' => 'browse', 'folder_id' => $this->oDocument->getFolderID())); // Electronic Signature if enabled global $default; if ($default->enableESignatures) { $widgets[] = array('ktcore.widgets.info', array('label' => _kt('This action requires authentication'), 'description' => _kt('Please provide your user credentials as confirmation of this action.'), 'name' => 'info')); $widgets[] = array('ktcore.widgets.string', array('label' => _kt('Username'), 'name' => 'sign_username', 'required' => true)); $widgets[] = array('ktcore.widgets.password', array('label' => _kt('Password'), 'name' => 'sign_password', 'required' => true)); } $widgets[] = array('ktcore.widgets.reason', array('label' => _kt('Reason'), 'description' => _kt('Please specify why you are copying this document. Bear in mind that you can use a maximum of <strong>250</strong> characters.'), 'name' => 'reason')); $oForm->setWidgets($widgets); $validators = array(); $validators[] = array('ktcore.validators.string', array('test' => 'reason', 'min_length' => 1, 'max_length' => 250, 'output' => 'reason')); $validators[] = array('ktcore.validators.entity', array('class' => 'Folder', 'test' => 'browse', 'output' => 'browse')); if ($default->enableESignatures) { $validators[] = array('electonic.signatures.validators.authenticate', array('object_id' => $this->oDocument->iId, 'type' => 'document', 'action' => 'ktcore.transactions.copy', 'test' => 'info', 'output' => 'info')); } $oForm->setValidators($validators); // here's the ugly bit. $err = $oForm->getErrors(); if (!empty($err['name']) || !empty($err['filename'])) { $oForm->addWidget(array('ktcore.widgets.string', array('label' => _kt('Document Title'), 'value' => sanitizeForHTML($this->oDocument->getName()), 'important_description' => _kt('Please indicate a new title to use to resolve any title conflicts.'), 'name' => 'name', 'required' => true))); $oForm->addValidator(array('ktcore.validators.string', array('output' => 'name', 'test' => 'name'))); $oForm->addWidget(array('ktcore.widgets.string', array('label' => _kt('Filename'), 'value' => sanitizeForHTML($this->oDocument->getFilename()), 'important_description' => _kt('Please indicate a new filename to use to resolve any conflicts.'), 'name' => 'filename', 'required' => true))); $oForm->addValidator(array('ktcore.validators.string', array('output' => 'filename', 'test' => 'filename'))); } return $oForm; }