.
/**
* This file contains the form for handling the layout of the htmlcert instance.
*
* @package mod_htmlcert
* @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_htmlcert;
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once($CFG->dirroot . '/course/moodleform_mod.php');
/**
* The form for handling the layout of the htmlcert instance.
*
* @package mod_htmlcert
* @copyright 2013 Mark Nelson , 2021 Klaus-Uwe Mitterer
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class edit_form extends \moodleform {
/**
* @var int The id of the template being used.
*/
protected $tid = null;
/**
* Form definition.
*/
public function definition() {
global $DB, $OUTPUT;
$mform =& $this->_form;
$mform->addElement('text', 'name', get_string('name', 'htmlcert'), 'maxlength="255"');
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required');
$mform->addElement('editor', 'html', get_string('html', 'htmlcert'));
$mform->setType('html', PARAM_RAW);
$mform->addRule('html', null, 'required');
// Add the submit buttons.
$group = array();
$group[] = $mform->createElement('submit', 'submitbtn', get_string('savechanges'));
$group[] = $mform->createElement('submit', 'previewbtn', get_string('savechangespreview', 'htmlcert'), array(), false);
$mform->addElement('group', 'submitbtngroup', '', $group, '', false);
$mform->addElement('hidden', 'tid');
$mform->setType('tid', PARAM_INT);
$mform->setDefault('tid', $this->tid);
}
/**
* Fill in the current page data for this htmlcert.
*/
public function definition_after_data() {
global $DB;
$mform = $this->_form;
}
/**
* Some basic validation.
*
* @param array $data
* @param array $files
* @return array the errors that were found
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (\core_text::strlen($data['name']) > 255) {
$errors['name'] = get_string('nametoolong', 'htmlcert');
}
return $errors;
}
/**
* Adds the page elements to the form.
*
* @param \stdClass $page the htmlcert page
*/
protected function add_htmlcert_page_elements($page) {
global $DB, $OUTPUT;
// Create the form object.
$mform =& $this->_form;
$editlink = '/mod/htmlcert/edit.php';
$editlinkparams = array('tid' => $this->tid, 'sesskey' => sesskey());
$mform->addElement('text', 'pagewidth', get_string('width', 'htmlcert'));
$mform->setType('pagewidth', PARAM_INT);
$mform->setDefault('pagewidth', '210');
$mform->addRule('pagewidth', null, 'required', null, 'client');
$mform->addHelpButton('pagewidth', 'width', 'htmlcert');
$mform->addElement('text', 'pageheight', get_string('height', 'htmlcert'));
$mform->setType('pageheight', PARAM_INT);
$mform->setDefault('pageheight', '297');
$mform->addRule('pageheight', null, 'required', null, 'client');
$mform->addHelpButton('pageheight', 'height', 'htmlcert');
}
}