I've created a custom Moodle block, with a basic form. I want to show a custom profile user field called 'custom_name'.
I'm using the basic form code from moodle Documentation (https://docs.moodle.org/dev/Form_API) :
//moodleform is defined in formslib.php
require_once("$CFG->libdir/formslib.php");
class simplehtml_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();
}
}
I simply need to show one custom input field ('profile_field_custom_name') and a submit button to save/update that data. If anyone could show me a similar finished example would be great. Thank you fory your help.