Aquesta pàgina forma part de la documentació de Moodle en català, tot i que no ha estat traduïda encara. Podeu contribuir obertament a les tasques de traducció. Podeu consultar la Guia d'edició de la documentació i també participar ens els debats del fòrum de traductors de la documentació a moodle.org

Broken/Patching forms tutorial

De MoodleDocs
La revisió el 14:57, 9 juny 2008 per Gary Anderson (discussió | contribucions) (Continued update of draft)
Salta a:navegació, cerca

by Gary Anderson

One of the easiest local modifications that an institution can make to customize their Moodle site is to make simple changes to the form elements that appear on pages. This permits one to set different default values when creating new items, allows one to hide unused input elements to simplify the interface, and lets one identify certain more complicated elements as "advanced" so that features are still availale while simplifying the interface for most uses.

This tutorial will demonstrate how to do such modifications.

Warning

Making custom changes to the PHP scripting code in Moodle should be done carefully. You should always test your code before using it on your production site and should backup the original scripts. You should always comment your code so you know what has been changed. Care should also be taken during upgrades in the code to make sure things are not broken (like conflicts during a CVS update).

Having said that, these patches are among the simplest and the recovery from an error is easy: simply replace the file with original from the core distribution.

Moodle Forms Overview

Rather than placing HTML form elements directly on the page, most well-written Moodle code will use the Forms Library. This allows a standard way to create user input elements and also centralizes code making it easier to override certain behaviors creating a greater consistency.

An entire form is an "object" with methods and attributes. In many places in the Moodle code, the instance of the object is identified my the variable $mform, but you can use any variable.

Common methods of the form object look like:

  • $mform->addelement(<elementtype>,<elementidentifier>,<displayname>,<options>);

This creates a new input element on a page.

While forms can be produced in any scripting page which outputs code, you will often find code for printing out forms in a file like mod_form.php or in index.php of the affected component.

Changing defaults

WRITE THIS NEXT


Hiding fields

==Setting fields to "Advanced""