Quantcast
Channel: General developer forum
Viewing all articles
Browse latest Browse all 37677

Re: Own mod_form.php

$
0
0
by Davo Smith.  

If you are wanting to create your own settings form, then take a look at the file mod_form.php in any of the existing Moodle activities (mod/page/mod_form.php is a fairly straightforward example).

Validation of input can be done via a 'validation()' function in the form (search for examples) or can be handled via 'addRule' calls in the form definition (again, search for examples)

The data is returned to your activity via the ACTIVITYNAME_add_instance and ACTIVITYNAME_update_instance functions in your activity's lib.php. e.g. mod/page/lib.php: page_add_instance() and page_update_instance().

If you really need a non-standard form element, then you can copy what is done in lib/form/*.php, but you will also need to somewhere call MoodleQuickForm::registerElementType (see lib/formslib.php - scroll down to the bottom). However, I'd recommend not doing this unless you really have to (the built-in types cover 95% of use cases).

Moodle handles initialising the form elements for you, assuming you give the fields in the database the same name as the form elements.


Viewing all articles
Browse latest Browse all 37677

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>