I am very new to moodle. I made a custom plugin for adding some custom feature. I made a custom form using moodle form api. This is the code for custom signup form usign moodleform- `
<?php
/*
* @package local_message
* @author Kristian
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
//moodleform is defined in formslib.php
require_once("$CFG->libdir/formslib.php");
class custom_signup_form extends moodleform {
//Add elements to form
public function definition() {
global $CFG;
$mform = $this->_form; // Don't forget the underscore!
$mform->addElement('text', 'email', get_string('email')); // Add elements to your form.
$mform->setType('email', PARAM_NOTAGS); // Set type of element.
$mform->setDefault('email', 'Please enter email'); // Default value.
}
//Custom validation should be added here
function validation($data, $files) {
return array();
}
}
Then I called that form in a php file to display -
<?php
/*
* @package local_message
* @author Kristian
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once($CFG->dirrot . '/local/custom_signup/classes/form/edit.php');
$PAGE->set_url(new moodle_url('/local/custom_signup/signupform.php'));
$PAGE->set_title(get_string('custom_signup', 'local_custom_signup'));
#custom form for signup
$mform = new custom_signup_form();
echo $OUTPUT->header();
$mform->display();
echo $OUTPUT->footer();
CodePudding user response:
By checking your error logs, You haven't added correct location. You need to verify the path to file.
Moreover, is $CFG->dirrot
spelling is correct? Isn't it $CFG->dirroot
?