1

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();

But it shows me that error - http error 500

Apache error log

If anyone knows what is happening here where did I made a mistake, would be very helpful for me. Thanks.

PHP error logo

Shihab
  • 17
  • 6
  • Go check what the PHP error log has to say. – CBroe Aug 01 '22 at 06:57
  • Thanks for your response. I shared an image of apache error log. Could you please check. – Shihab Aug 01 '22 at 07:00
  • The web server log does not contain anything that appears even remotely relevant to your problem. Go check what the PHP error log has to say. – CBroe Aug 01 '22 at 07:04
  • Hi CBroe. I have enabled PHP error log - Notice: Undefined property: stdClass::$dirrot in C:\xampp\htdocs\moodle\local\custom_signup\signupform.php on line 11 Warning: require_once(/local/custom_signup/classes/form/edit.php): failed to open stream: No such file or directory in C:\xampp\htdocs\moodle\local\custom_signup\signupform.php on line 11 Fatal error: require_once(): Failed opening required '/local/custom_signup/classes/form/edit.php' (include_path='C:\xampp\htdocs\moodle/lib/pear;C:\xampp\php\PEAR') in C:\xampp\htdocs\moodle\local\custom_signup\signupform.php on line 11 – Shihab Aug 01 '22 at 07:48
  • @CBroe I have added another picture after enabling PHP error log. See if that can help you understand. Thanks again. – Shihab Aug 01 '22 at 07:55
  • `$CFG->dirrot` appears to be empty, and therefor the `require_once` statement tries to find the file under the wrong path, resulting in a fatal error. – CBroe Aug 01 '22 at 07:58
  • @CBroe now I get it. Thanks for helping. – Shihab Aug 01 '22 at 08:03

1 Answers1

2

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?