How to add fields and change required fields in moodle signup form?

118 Views Asked by At

I have a moodle project as a developer and i want to change the sign up form to make it simpler.Bascially, i want to remove the username field and replace it with a full name field and add a phone number field that is not mandatory (required) and remove all the other unnecessary fields or at least set them as not required sign up form current

I have hid some of the unnecessary features using CSS but i want something more functional, and want to know what files i need to change to make the changes in the backend so that it works as expected when a user signs up. Any help/advice with this would be greatly appreciated!

1

There are 1 best solutions below

2
davosmith On

There is a hook in Moodle core to handle this.

Create a plugin (probably a 'local' plugin) and make sure its lib.php has a function local_myplugin_extend_signup_form() (where 'local_myplugin' is the Frankenstyle name of your plugin).

Within this function, you can use the $mform instance passed in to call functions such as $mform->addElement(), $mform->insertElementBefore() and $mform->removeElement() to modify the existing form.

You may need to use local_myplugin_post_signup_requests() to modify the data, so that it matches the expected data from the form (you will need to generate a 'username' field of some kind), as well as using local_myplugin_validate_extend_signup_form() to adjust the validation (as the submission normally validates to make sure the username is present).