<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/21/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marxjohnson</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/21/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Marxjohnson"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/Special:Contributions/Marxjohnson"/>
	<updated>2026-04-13T22:49:45Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Performance_recommendations&amp;diff=87226</id>
		<title>Performance recommendations</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Performance_recommendations&amp;diff=87226"/>
		<updated>2011-08-08T12:59:39Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Removed warning about unsupported versions of IE and SSL Keepalive&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Server settings}}&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;&#039;Please refer to [[Page_notes#Server settings|these notes]] before editing this page.&#039;&#039;&#039;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Location: &#039;&#039;Administration &amp;gt; Server &amp;gt; Performance&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Moodle can be made to perform very well, at small usage levels or scaling up to many thousands of users. The factors involved in performance are basically the same as for any PHP-based database-driven system. When trying to optimize your server, try to focus on the factor which will make the most difference to the user. For example, if you have relatively more users browsing than accessing the database, look to improve the webserver performance.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Obtain a baseline benchmark==&lt;br /&gt;
&lt;br /&gt;
Before attempting any optimization, you should obtain a baseline benchmark of the component of the system you are trying to improve. For Linux try [http://lbs.sourceforge.net/ LBS] and for Windows use the Performance Monitor. Once you have quantitative data about how your system is performing currently, you&#039;ll be able to determine if the change you have made has had any real impact.&lt;br /&gt;
&lt;br /&gt;
The overall aim of adjustments to improve performance is to use RAM (cacheing) and to reduce disk-based activity. It is especially important to try to eliminate swap file usage as much as you can. If your system starts swapping, this is a sign that you need more RAM. &lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;optimization order preference&#039;&#039;&#039; is usually: primary storage (more RAM), secondary storage (faster hard disks/improved hard disk configuration), processor (more and faster).&lt;br /&gt;
&lt;br /&gt;
==Scalability==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s design (with clear separation of application layers) allows for strongly scalable setups. (Please check the list of [[Large installations|large Moodle installations]].)&lt;br /&gt;
&lt;br /&gt;
Large sites usually separate the web server and database onto separate servers, although for smaller installations this is typically not necessary.&lt;br /&gt;
&lt;br /&gt;
It is possible to load-balance a Moodle installation, for example by using more than one webserver. The separate webservers should query the same database and refer to the same filestore area, but otherwise the separation of the application layers is complete enough to make this kind of clustering feasible. Similarly, the database could be a cluster of servers (e.g. a MySQL cluster), but this is not an easy task and you should seek expert support, e.g. from a Moodle Partner.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;See also&#039;&#039;&#039;: &lt;br /&gt;
*[[Server cluster]]&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=4801 Scalability] forum discussion.&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=57202 Moodle clustering] forum discussion.&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=44470 Software load balancing] forum discussion.&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=49986 TCP load balancing] forum dicsussion.&lt;br /&gt;
&lt;br /&gt;
==Hardware configuration==&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: The fastest and most effective change that you can make to improve performance is to &#039;&#039;&#039;increase the amount of RAM on your web server&#039;&#039;&#039; - get as much as possible (eg 4GB). Increasing primary memory will reduce the need for processes to swap to disk and will enable your server to handle more users.&lt;br /&gt;
* Better performance is gained by obtaining the best &#039;&#039;&#039;processor capability&#039;&#039;&#039; you can, i.e. dual or dual core processors. A modern BIOS should allow you to enable hyperthreading, but check if this makes a difference to the overall performance of the processors by using a [http://en.wikipedia.org/wiki/Super_PI CPU benchmarking tool].&lt;br /&gt;
* If you can afford them, use &#039;&#039;&#039;SCSI hard disks&#039;&#039;&#039; instead of SATA drives. SATA drives will increase your system&#039;s CPU utilization, whereas SCSI drives have their own integrated processors and come into their own when you have multiple drives. If you must have SATA drives, check that your motherboard and the drives themselves support NCQ (Native Command Queuing).&lt;br /&gt;
* Purchase hard disks with a &#039;&#039;&#039;low seek time&#039;&#039;&#039;. This will improve the overall speed of your system, especially when accessing Moodle&#039;s reports.&lt;br /&gt;
* Size your &#039;&#039;&#039;swap file&#039;&#039;&#039; correctly. The general advice is to set it to 4 x physical RAM.&lt;br /&gt;
* Use a &#039;&#039;&#039;RAID disk system&#039;&#039;&#039;. Although there are many different RAID configurations you can create, the following generally works best:&lt;br /&gt;
** install a hardware RAID controller (if you can)&lt;br /&gt;
** the operating system and swap drive on one set of disks configured as RAID-1.&lt;br /&gt;
** Moodle, Web server and Database server on another set of disks configured as RAID-5.&lt;br /&gt;
* Use &#039;&#039;&#039;gigabit ethernet&#039;&#039;&#039; for improved latency and throughput. This is especially important when you have your webserver and database server separated out on different hosts.&lt;br /&gt;
* Check the settings on your &#039;&#039;&#039;network card&#039;&#039;&#039;. You may get an improvement in performance by increasing the use of buffers and transmit/receive descriptors (balance this with processor and memory overheads) and off-loading TCP checksum calculation onto the card instead of the OS.&lt;br /&gt;
*  Read this [http://moodle.org/mod/forum/discuss.php?d=68579 Case Study] on a server stress test with 300 users.  &lt;br /&gt;
* See this [http://elearning.sgu.ac.jp/doc/PT/ accompanying report] on network traffic and server loads.&lt;br /&gt;
* See the [[Moodle.org configuration]]&lt;br /&gt;
* Also see this SFSU presentation at Educause (using VMWare): [http://www.educause.edu/Resources/AnOpenSourceLMSforaMissionCrit/162843]&lt;br /&gt;
&lt;br /&gt;
==Operating System==&lt;br /&gt;
* You can use [http://en.wikipedia.org/wiki/Linux Linux](recommended), Unix-based, Windows or Mac OS X for the server &#039;&#039;&#039;operating system&#039;&#039;&#039;. *nix operating systems generally require less memory than Mac OS X or Windows servers for doing the same task as the server is configured with just a shell interface. Additionally Linux does not have licensing fees attached, but can have a big learning curve if you&#039;re used to another operating system. If you have a large number of processors running SMP, you may also want to consider using a highly tuned OS such as [http://en.wikipedia.org/wiki/Solaris_Operating_Environment Solaris].&lt;br /&gt;
* Check your own OS and &#039;&#039;&#039;vendor specific instructions&#039;&#039;&#039; for optimization steps.&lt;br /&gt;
** For Linux look at the [http://linuxperf.sourceforge.net/ Linux Performance Team] site. &lt;br /&gt;
** For Linux investigate the hdparm command, e.g. hdparm -m16 -d1 can be used to enable read/write on multiple sectors and DMA. Mount disks with the async and noatime options.&lt;br /&gt;
** For Windows set the sever to be optimized for network applications (Control Panel, Network Connections, LAN connection, Properties, File &amp;amp; Printer Sharing for Microsoft Networks, Properties, Optimization). You can also search the [http://technet.microsoft.com/ Microsoft TechNet site] for optimization documents.&lt;br /&gt;
&lt;br /&gt;
==Web server performance==&lt;br /&gt;
&lt;br /&gt;
Installing [http://www.mozilla.com/en-US/ Firefox] and the [https://addons.mozilla.org/en-US/firefox/addon/1843 firebug] extension will allow you to watch the time it takes for each page component to load. Also, the [https://addons.mozilla.org/en-US/firefox/addon/5369 Yslow] extension will evaluate your page against Yahoo&#039;s [http://www.skrenta.com/2007/05/14_rules_for_fast_web_pages_by_1.html 14 rules], full text [http://developer.yahoo.com/performance/rules.html Best Practices for Speeding Up Your Web Site], &amp;lt;strike&amp;gt;([http://video.yahoo.com/video/play?vid=1040890 video])&amp;lt;/strike&amp;gt; for fast loading websites.&lt;br /&gt;
&lt;br /&gt;
===PHP performance===&lt;br /&gt;
* You are strongly recommended to use a &#039;&#039;&#039;PHP accelerator&#039;&#039;&#039; to ease CPU load, such as [http://pecl.php.net/apc APC], [http://www.php-accelerator.co.uk/ PHPA], [http://trac.lighttpd.net/xcache/ Xcache] or [http://eaccelerator.net/ eAccelerator]. (Take care to choose a PHP accelerator that is known to work well with your version of PHP and note that Turck MMCache is [http://turckmmcache.exeprod.com/TheManifestoEnglish no longer maintained] and can cause failures with PHP 5). &lt;br /&gt;
* Improvements in read/write performance can be improved by putting the cached PHP pages on a [[TMPFS]] filesystem - but remember that you&#039;ll lose the cache contents when there is a power failure or the server is rebooted.&lt;br /&gt;
* Performance of PHP is better when installed as an &#039;&#039;&#039;Apache/IIS ISAPI module&#039;&#039;&#039; (rather than a CGI).&lt;br /&gt;
* Also check the &#039;&#039;&#039;memory_limit&#039;&#039;&#039; in php.ini, reduce it to 16M for Moodle version earlier than 1.7 ([http://moodle.org/mod/forum/discuss.php?d=39656 See this forum discussion]). For Moodle 1.7 or later, it is recommended that the value of memory_limit should be 40M. As of [http://www.php.net/ChangeLog-5.php PHP 5.2.1] the default value for the memory_limit directive is 128M.&lt;br /&gt;
* Also see [[PHP_settings_by_Moodle_version]]&lt;br /&gt;
&lt;br /&gt;
===Install HowTo===&lt;br /&gt;
* [http://2bits.com/articles/installing-php-apc-gnulinux-centos-5.html APC on CentOS 5.x (linux)]&lt;br /&gt;
* [http://fplanque.com/dev/linux/install-apc-php-cache-debian-lenny APC on Debian (linux)]&lt;br /&gt;
* [http://www.linuxtuts.net/211-installing-memcached-php5-memcache-module-debian-apache2.html MemCache module on Debian (Apache2 and PHP5) ]&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/03/installing-memcached-on-centos-5x.html Installing Memcache on CentOS 5.x (linux)]&lt;br /&gt;
* [http://noveckg.blogspot.com/2010/02/installing-eaccelerator-cache-for-php.html Installing eAccelerator on CentOS 5.x (linux)]&lt;br /&gt;
* [https://docs.moodle.org/en/Installing_eAccelerator_In_Ubuntu_Server/ Installing eAccelerator on Ubuntu Server (linux)]&lt;br /&gt;
&lt;br /&gt;
===Apache performance===&lt;br /&gt;
* If you are using Apache on a Windows server, use the build from [http://www.apachelounge.com Apache Lounge] which is reported to have [http://moodle.org/mod/forum/discuss.php?d=93358 performance and stability improvements] compared to the official Apache download. Note that this is an unofficial build, so may not keep up with official releases.&lt;br /&gt;
* Set the &#039;&#039;&#039;MaxClients&#039;&#039;&#039; directive correctly. Use this formula to help (which uses 80% of available memory to leave room for spare):&lt;br /&gt;
 MaxClients = Total available memory * 80% / Max memory usage of apache process&lt;br /&gt;
:Memory usage of apache process is usually 10MB, so a general rule of thumb is to divide your available memory in megabytes by 10 to get the value of MaxClients. To find the max memory usage of apache processes read the value from the shell command:&lt;br /&gt;
 #ps -ylC httpd --sort:rss&lt;br /&gt;
&lt;br /&gt;
:If you need to increase the value of &#039;&#039;&#039;MaxClients&#039;&#039;&#039; beyond 256, you will also need to set the &#039;&#039;&#039;ServerLimit&#039;&#039;&#039; directive. &lt;br /&gt;
&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: Do not be tempted to set the value of MaxClients higher than your available memory as your server will consume more RAM than available and start to swap to disk. &lt;br /&gt;
* Consider reducing the &#039;&#039;&#039;number of modules&#039;&#039;&#039; that Apache loads in the httpd.conf file to the minumum necessary to reduce the memory needed. &lt;br /&gt;
* Use the &#039;&#039;&#039;latest version of Apache&#039;&#039;&#039; - Apache 2 has an improved memory model which reduces memory usage further.&lt;br /&gt;
* For Unix/Linux systems, consider lowering &#039;&#039;&#039;MaxRequestsPerChild&#039;&#039;&#039; in httpd.conf to as low as 20-30 (if you set it any lower the overhead of forking begins to outweigh the benefits). &lt;br /&gt;
* For a heavily loaded server, consider setting &#039;&#039;&#039;KeepAlive Off&#039;&#039;&#039; (do this only if your Moodle pages do not contain links to resources or uploaded images) or lowering the &#039;&#039;&#039;KeepAliveTimeout&#039;&#039;&#039; to between 2 and 5. The default is 15 (seconds) - the higher the value the more server processes will be kept waiting for possibly idle connections. A more accurate value for KeepAliveTimeout is obtained by observing how long it takes your users to download a page. After altering any of the KeepAlive variables, monitor your CPU utilization as there may be an additional overhead in initiating more worker processes/threads.&lt;br /&gt;
* As an alternative to using KeepAlive Off, consider setting-up a &#039;&#039;&#039;Reverse Proxy server&#039;&#039;&#039; infront of the Moodle server to cache HTML files with images. You can then return Apache to using keep-alives on the Moodle server.&lt;br /&gt;
* If you do not use a .htaccess file, set the &#039;&#039;&#039;AllowOverride&#039;&#039;&#039; variable to AllowOverride None to prevent .htaccess lookups.&lt;br /&gt;
* Set &#039;&#039;&#039;DirectoryIndex&#039;&#039;&#039; correctly so as to avoid content-negotiation. Here&#039;s an example from a production server:&lt;br /&gt;
 DirectoryIndex index.php index.html index.htm&lt;br /&gt;
* Unless you are doing development work on the server, set &#039;&#039;&#039;ExtendedStatus Off&#039;&#039;&#039; and disable mod_info as well as mod_status.&lt;br /&gt;
* Leave &#039;&#039;&#039;HostnameLookups Off&#039;&#039;&#039; (as default) to reduce DNS latency.&lt;br /&gt;
* Consider reducing the value of &#039;&#039;&#039;TimeOut&#039;&#039;&#039; to between 30 to 60 (seconds). &lt;br /&gt;
* For the &#039;&#039;&#039;Options directive&#039;&#039;&#039;, avoid Options Multiviews as this performs a directory scan. To reduce disk I/O further use&lt;br /&gt;
 Options -Indexes FollowSymLinks&lt;br /&gt;
*&#039;&#039;&#039;Caching (unsupported)&#039;&#039;&#039; - &#039;&#039;Please note that this kind of caching may create major problems during upgrades.&#039;&#039; Apache can be told to make pages load a lot faster by specifying that the browser should cache some various page elements such as images and reuse them from local memory rather than ask for them again every time a page is requested. How to do this varies slightly between OSes but there are two basic steps:&lt;br /&gt;
&lt;br /&gt;
# Install and enable mod_expires - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;IfModule mod_expires.c&amp;gt;&lt;br /&gt;
  ExpiresActive On&lt;br /&gt;
  ExpiresDefault &amp;quot;access plus 1 seconds&amp;quot;&lt;br /&gt;
  ExpiresByType text/html &amp;quot;access plus 1 seconds&amp;quot;&lt;br /&gt;
  ExpiresByType image/gif &amp;quot;access plus 1 week&amp;quot;&lt;br /&gt;
  ExpiresByType image/jpeg &amp;quot;access plus 1 week&amp;quot;&lt;br /&gt;
  ExpiresByType image/png &amp;quot;access plus 1 week&amp;quot;&lt;br /&gt;
  ExpiresByType text/css &amp;quot;access plus 1 week&amp;quot;&lt;br /&gt;
  ExpiresByType text/javascript &amp;quot;access plus 1 week&amp;quot;&lt;br /&gt;
  ExpiresByType application/x-javascript &amp;quot;access plus 1 week&amp;quot;&lt;br /&gt;
  ExpiresByType text/xml &amp;quot;access plus 1 seconds&amp;quot;&lt;br /&gt;
 &amp;lt;/IfModule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The effect is to make everything stay in the cache except HTML and XML, which change dynamically. It&#039;s possible to gain a several hundred percent decrease in load times this way. Adjust the cache times according to how often your images etc change.&lt;br /&gt;
&lt;br /&gt;
* Compression reduces response times by reducing the size of the HTTP response&lt;br /&gt;
# Install and enable mod_deflate - refer to documentation or man pages&lt;br /&gt;
# Add this code to the virtual server config file within the &amp;lt;directory&amp;gt; section for the root directory (or within the .htaccess file if AllowOverrides is On):&lt;br /&gt;
 &amp;lt;ifModule mod_deflate.c&amp;gt;&lt;br /&gt;
   AddOutputFilterByType DEFLATE text/html text/plain text/xml&lt;br /&gt;
 &amp;lt;/ifmodule&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More info: [http://www.metaskills.net/blog/heuristics/sysadmin/how-to-control-browser-caching-with-apache-2 www.metaskills.net]&lt;br /&gt;
&lt;br /&gt;
===IIS performance===&lt;br /&gt;
All alter this location in the registry:&lt;br /&gt;
 HKLM\SYSTEM\CurrentControlSet\Services\Inetinfo\Parameters\&lt;br /&gt;
* The equivalent to KeepAliveTimeout is &#039;&#039;&#039;ListenBackLog&#039;&#039;&#039; (IIS - registry location is HKLM\ SYSTEM\ CurrentControlSet\ Services\ Inetinfo\ Parameters). Set this to between 2 to 5.&lt;br /&gt;
*Change the &#039;&#039;&#039;MemCacheSize&#039;&#039;&#039; value to adjust the amount of memory (Mb) that IIS will use for its file cache (50% of available memory by default).&lt;br /&gt;
*Change the &#039;&#039;&#039;MaxCachedFileSize&#039;&#039;&#039; to adjust the maximum size of a file cached in the file cache in bytes. Default is 262,144 (256K).&lt;br /&gt;
*Create a new DWORD called &#039;&#039;&#039;ObjectCacheTTL&#039;&#039;&#039; to change the length of time (in milliseconds) that objects in the cache are held in memory. Default is 30,000 milliseconds (30 seconds).&lt;br /&gt;
&lt;br /&gt;
===Lighttpd, NginX and Cherokee performance===&lt;br /&gt;
You can increase server performance by using a &#039;&#039;&#039;light-weight&#039;&#039;&#039; webserver like [http://www.lighttpd.net/ lighttpd],  [http://nginx.net/ nginx] or [http://www.cherokee-project.com/ cherokee] in combination with PHP in FastCGI-mode. Lighttpd was originally created as a proof-of-concept[http://www.lighttpd.net/story] to address the [http://www.kegel.com/c10k.html C10k problem] and while primarily recommended for memory-limited servers, its design origins and asynchronous-IO model make it a suitable and proven[http://blog.lighttpd.net/articles/2006/12/28/lighttpd-powers-5-alexa-top-250-sites] alternative HTTP server for high-load websites and web apps, including Moodle. See the [[lighttpd | MoodleDocs Lighttpd page]] for additional information, configuration example and links.&lt;br /&gt;
&lt;br /&gt;
Alternatively, both [http://www.lighttpd.net/ lighttpd] and [http://nginx.net/ nginx] are capable of performing as a load-balancer and/or reverse-proxy to alleviate load on back-end servers[http://www.linuxjournal.com/article/10108], providing benefit without requiring an actual software change on existing servers.&lt;br /&gt;
&lt;br /&gt;
Do note that these are likely to be the least tested server environments of all particularly if you are using advanced features such as web services and/or Moodle Networking. They are probably best considered for heavily used Moodle sites with relatively simple configurations.&lt;br /&gt;
&lt;br /&gt;
==Database performance==&lt;br /&gt;
&lt;br /&gt;
Moodle contains a script which will display some key database performance statistics from the [http://phplens.com/lens/adodb/docs-perf.htm ADOdb performance monitor]. Run the script in your browser as in the following example:&lt;br /&gt;
&lt;br /&gt;
 http://www.mymoodle.com/admin/dbperformance.php&lt;br /&gt;
&lt;br /&gt;
Use the data displayed as a guide to tune and improve the performance of your database server.&lt;br /&gt;
&lt;br /&gt;
===MySQL performance===&lt;br /&gt;
&lt;br /&gt;
The following are MySQL specific settings which can be adjusted for better performance in your my.cnf (my.ini in Windows). The file contains a list of settings and their values. To see the current values use these commands&lt;br /&gt;
 SHOW STATUS;&lt;br /&gt;
 SHOW VARIABLES; &lt;br /&gt;
&#039;&#039;&#039;Important&#039;&#039;&#039;: You must make backups of your database before attempting to change any MySQL server configuration. After any change to the my.cnf, restart mysqld.&lt;br /&gt;
&lt;br /&gt;
If you are able, the [http://mysqltuner.com/ MySQLTuner] tool can be run against your MySQL server and will calculate appropriate configuration values for most of the following settings based on your current load, status and variables automatically.&lt;br /&gt;
&lt;br /&gt;
* Enable the &#039;&#039;&#039;query cache&#039;&#039;&#039; with &lt;br /&gt;
 query_cache_type = 1. &lt;br /&gt;
For most Moodle installs, set the following:&lt;br /&gt;
 query_cache_size = 36M &lt;br /&gt;
 query_cache_min_res_unit = 2K. &lt;br /&gt;
The query cache will improve performance if you are doing few updates on the database. &lt;br /&gt;
* Set the &#039;&#039;&#039;table cache&#039;&#039;&#039; correctly. For Moodle 1.6 set &lt;br /&gt;
 table_cache = 256 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min), and for Moodle 1.7 set &lt;br /&gt;
 table_cache = 512 #(table_open_cache in MySQL &amp;gt; 5.1.2)&lt;br /&gt;
(min). The table cache is used by all threads (connections), so monitor the value of opened_tables to further adjust - if opened_tables &amp;gt; 3 * table_cache(table_open_cache in MySQL &amp;gt; 5.1.2) then increase table_cache upto your OS limit. Note also that the figure for table_cache will also change depending on the number of modules and plugins you have installed. Find the number for your server by executing the mysql statement below. Look at the number returned and set table_cache to this value.&lt;br /&gt;
 mysql&amp;gt;SELECT COUNT(table_name) FROM information_schema.tables WHERE table_schema=&#039;yourmoodledbname&#039;;&lt;br /&gt;
* Set the &#039;&#039;&#039;thread cache&#039;&#039;&#039; correctly. Adjust the value so that your thread cache utilization is as close to 100% as possible by this formula:&lt;br /&gt;
 thread cache utilization (%) = (threads_created / connections) * 100&lt;br /&gt;
* The &#039;&#039;&#039;key buffer&#039;&#039;&#039; can improve the access speed to Moodle&#039;s SELECT queries. The correct size depends on the size of the index files (.myi) and in Moodle 1.6 or later (without any additional modules and plugins), the recommendation for this value is key_buffer_size = 32M. Ideally you want the database to be reading once from the disk for every 100 requests so monitor that the value is suitable for your install by adjusting the value of key_buffer_size so that the following formulas are true:&lt;br /&gt;
 key_read / key_read_requests &amp;lt; 0.01&lt;br /&gt;
 key_write / key_write_requests &amp;lt;= 1.0&lt;br /&gt;
* Set the &#039;&#039;&#039;maximum number of connections&#039;&#039;&#039; so that your users will not see a &amp;quot;Too many connections&amp;quot; message. Be careful that this may have an impact on the total memory used. MySQL connections usually last for milliseconds, so it is unusual even for a heavily loaded server for this value to be over 200.&lt;br /&gt;
* Manage &#039;&#039;&#039;high burst activity&#039;&#039;&#039;. If your Moodle install uses a lot of quizzes and you are experiencing performance problems (check by monitoring the value of threads_connected - it should not be rising) consider increasing the value of back_log.&lt;br /&gt;
* &#039;&#039;&#039;Optimize your tables weekly and after upgrading Moodle&#039;&#039;&#039;. It is good practice to also optimize your tables after performing a large data deletion exercise, e.g. at the end of your semester or academic year. This will ensure that index files are up to date. Backup your database first and then use:&lt;br /&gt;
 mysql&amp;gt;CHECK TABLE mdl_tablename;&lt;br /&gt;
 mysql&amp;gt;OPTIMIZE TABLE mdl_tablename;&lt;br /&gt;
:The common tables in Moodle to check are mdl_course_sections, mdl_forum_posts, mdl_log and mdl_sessions (if using dbsessions). Any errors need to be corrected using REPAIR TABLE (see the [http://dev.mysql.com/doc/refman/5.0/en/repair-table.html MySQL manual] and this [http://moodle.org/mod/forum/discuss.php?d=58208#p279638 forum script]).&lt;br /&gt;
* &#039;&#039;&#039;Maintain the key distribution&#039;&#039;&#039;. Every month or so it is a good idea to stop the mysql server and run these myisamchk commands.&lt;br /&gt;
 #myisamchk -a -S /pathtomysql/data/moodledir/*.MYI&lt;br /&gt;
:&#039;&#039;&#039;Warning&#039;&#039;&#039;: You must stop the mysql database process (mysqld) before running any myisamchk command. If you do not, you risk data loss.&lt;br /&gt;
* Reduce the number of &#039;&#039;&#039;temporary tables saved to disk&#039;&#039;&#039;. Check this with the created_tmp_disk_tables value. If this is relatively large (&amp;gt;5%) increase tmp_table_size until you see a reduction. Note that this will have an impact on RAM usage.&lt;br /&gt;
&lt;br /&gt;
===PostgreSQL performance===&lt;br /&gt;
&lt;br /&gt;
There are some good papers around on tuning PostgreSQL, and Moodle&#039;s case does not seem to be different to the general case.&lt;br /&gt;
&lt;br /&gt;
The first thing to recognise is that if you really need to worry about tuning you should be using a separate machine for the database server. If you are not using a separate machine then the answers to many performance questions are substantially muddied by the memory requirements of the rest of the application.&lt;br /&gt;
&lt;br /&gt;
You should probably &#039;&#039;&#039;enable autovacuum&#039;&#039;&#039;, unless you know what you are doing. Many e-learning sites have predictable periods of low use, so disabling autovacuum and running a specific vacuum at those times can be a good option. Or perhaps leave autovacuum running but do a full vacuum weekly in a quiet period.&lt;br /&gt;
&lt;br /&gt;
Set &#039;&#039;&#039;shared_buffers&#039;&#039;&#039; to something reasonable. For versions up to 8.1 my testing has shown that peak performance is almost always obtained with buffers &amp;lt; 10000, so if you are using such a version, and have more than 512M of RAM just set shared_buffers to 10,000 (8MB).&lt;br /&gt;
&lt;br /&gt;
The buffer management had a big overhaul in 8.2 and &amp;quot;reasonable&amp;quot; is now a much larger number. I have not conducted performance tests with 8.2, but the recommendations from others are generally that you should now scale shared_buffers much more with memory and may continue to reap benefits even up to values like 100,000 (80MB). Consider using 1-2% of system RAM.&lt;br /&gt;
&lt;br /&gt;
PostgreSQL will also assume that the operating system is caching its files, so setting &#039;&#039;&#039;effective_cache_size&#039;&#039;&#039; to a reasonable value is also a good idea. A reasonable value will usually be (total RAM - RAM in use by programs). If you are running Linux and leave the system running for a day or two you can look at &#039;free&#039; and under the &#039;cached&#039; column you will see what it currently is. Consider taking that number (which is kB) and dividing it by 10 (i.e. allow 20% for other programs cache needs and then divide by 8 to get pages). If you are not using a dedicated database server you will need to decrease that value to account for usage by other programs.&lt;br /&gt;
&lt;br /&gt;
Some other useful parameters that can have positive effects, and the values I would typically set them to on a machine with 4G RAM, are:&lt;br /&gt;
&lt;br /&gt;
 work_mem = 10240&lt;br /&gt;
&lt;br /&gt;
That&#039;s 10M of RAM to use instead of on-disk sorting and so forth. That can give a big speed increase, but it is per connection and 200 connections * 10M is 2G, so it can theoretically chew up a lot of RAM.&lt;br /&gt;
&lt;br /&gt;
 maintenance_work_mem = 163840&lt;br /&gt;
&lt;br /&gt;
That&#039;s 160M of RAM which will be used by (e.g.) VACUUM, index rebuild, cluster and so forth. This should only be used periodically and should be freed when those processes exit, so I believe it is well worth while.&lt;br /&gt;
&lt;br /&gt;
 max_fsm_pages = 100000&lt;br /&gt;
 max_fsm_relations = 5000&lt;br /&gt;
&lt;br /&gt;
These are used to hold the free-space map, and if they are too small you will see performance degradation after the database has been operating for some time. The exact numbers to set can be gleaned from the output of VACUUM VERBOSE, which prints the required FSM pages at the end of it&#039;s run. The 5x increase seems to be useful for a Moodle installation, from experience.&lt;br /&gt;
&lt;br /&gt;
 wal_buffers = 64&lt;br /&gt;
&lt;br /&gt;
These buffers are used for the write-ahead log, and there have been a number of reports on the PostgreSQL mailing lists of improvement from this level of increase.&lt;br /&gt;
&lt;br /&gt;
This is a little out of date now (version 8.0) but still worth a read: http://www.powerpostgresql.com/Docs&lt;br /&gt;
&lt;br /&gt;
And there is lots of good stuff here as well: http://www.varlena.com/GeneralBits/Tidbits/index.php&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Based on Andrew McMillan&#039;s post at [http://moodle.org/mod/forum/discuss.php?d=68558 Tuning PostgreSQL] forum thread.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
===Other database performance links===&lt;br /&gt;
* Consider using a &#039;&#039;&#039;distributed cacheing system&#039;&#039;&#039; like [http://en.wikipedia.org/wiki/Memcached memcached] but note that memcached does not have any security features so it should be used behind a firewall.&lt;br /&gt;
* Consider using PostgreSQL. See [[Arguments in favour of PostgreSQL]] and [http://moodle.org/mod/forum/discuss.php?d=49195 how to migrate from MySQL to PostgreSQL] (forum discussion).&lt;br /&gt;
* [[Increasing the database connection lifetime | Try increasing the database connection lifetime]]&lt;br /&gt;
* [http://dev.mysql.com/doc/refman/5.0/en/server-parameters.html General advice on tuning MySQL parameters] (advice from the MySQL manual)&lt;br /&gt;
* [http://www.mysqlperformanceblog.com/2007/11/01/innodb-performance-optimization-basics/ InnoDB performance optimization] taken from the [http://www.mysqlperformanceblog.com/ MySQL performance blog] site.&lt;br /&gt;
&lt;br /&gt;
==Moodle Admin settings==&lt;br /&gt;
* In Moodle 1.7 or later, set the &#039;&#039;&#039;Cache type&#039;&#039;&#039; for your server: Site Admin -&amp;gt; Server -&amp;gt; Performance -&amp;gt; Cache type. There are several options available. &lt;br /&gt;
:*If you do not have eaccelerator or mmemcached installed, choose &amp;quot;internal&amp;quot; (which makes use of the record/internal cache - see the next bullet point). &lt;br /&gt;
:* If you have a single server and have compiled &#039;&#039;&#039;eaccelerator with shared memory support&#039;&#039;&#039;, set the cache type to the eaccelerator option. &lt;br /&gt;
:* If you have a &#039;&#039;&#039;separate memcached server&#039;&#039;&#039;, set the cache type to memcached and enter a csv list of server IP addresses.&lt;br /&gt;
* Enable the &#039;&#039;&#039;record/internal cache&#039;&#039;&#039;: Site Admin -&amp;gt; Server -&amp;gt; Performance -&amp;gt; Record cache = True. Set the maximum amount of memory allocated to the cache in the Int Cache Max box. This will enable a primary cache for database records, without using any database engine cache, e.g. MySQL/PostgreSQL cache. See [http://tracker.moodle.org/browse/MDL-7196 this Tracker entry] for a full discussion.&lt;br /&gt;
* Enable the &#039;&#039;&#039;language cache&#039;&#039;&#039;.&lt;br /&gt;
* Large log files can cause overall performance to degrade over time. If you observe that the site has gradually got slower loading pages in the browser, &#039;&#039;&#039;reduce your Log life time&#039;&#039;&#039; setting (Admin/Server/Cleanup).&lt;br /&gt;
* Performance can be greatly improved by allowing Moodle to use the system &#039;&#039;&#039;zip/unzip&#039;&#039;&#039; commands (rather than PHP-based zip libraries) - visit Admin/Server/System Paths and enter the path to the relevant executables. (Similarly, filling in the path to &#039;&#039;&#039;du&#039;&#039;&#039; will improve Moodle&#039;s speed at listing directory contents.)&lt;br /&gt;
* Note that using &#039;&#039;&#039;secure web connections&#039;&#039;&#039; (&#039;&#039;&#039;https&#039;&#039;&#039; rather than &#039;&#039;&#039;http&#039;&#039;&#039;) carries a higher processing burden, both for the webserver and the client - particularly because cacheing cannot be used as effectively, so the number of file requests is likely to increase dramatically. For this reason using https for all Moodle pages is not recommended. You can enable https just for the login screen, simply from Moodle&#039;s config page.&lt;br /&gt;
* Check your &#039;&#039;&#039;filters&#039;&#039;&#039;. Having too many filters active can have serious effects on server load, especially on lower-end systems. The number of active filters has a direct effect on the perceived latency of your site; that is the time taken for each page impression. &lt;br /&gt;
* Enable the &#039;&#039;&#039;text cache&#039;&#039;&#039; but do not &amp;quot;Filter all strings&amp;quot; unless you have a specific need. If in doubt profile the performance, and see how your changes affect the processing time.&lt;br /&gt;
* Check your &#039;&#039;&#039;anti-virus&#039;&#039;&#039; measures on the server.  Although they are useful for preventing security holes being exploited, some &amp;quot;On-Demand&amp;quot; scanners can affect performance by scanning page content (word, ppt files etc).&lt;br /&gt;
* If there are performance problems loading course pages, check the &#039;&#039;&#039;Resource module settings&#039;&#039;&#039;. The setting resource_filterexternalpages is known to slow-down course pages and should be set to &#039;No&#039; for better performance.&lt;br /&gt;
* Check your &#039;&#039;&#039;forum settings&#039;&#039;&#039;. To improve performance set forum_trackreadposts = No and forum_usermarksread = Yes (this will impact on the convenience of your users&#039; forum experience). Also consider setting the time of the day when old posts are cleared from the read table (forum_cleanreadtime) to when your site is less busy.&lt;br /&gt;
* Don&#039;t use database sessions unless you really need them. On-disc sessions tend to be much faster.&lt;br /&gt;
&lt;br /&gt;
==Performance of different Moodle modules==&lt;br /&gt;
&lt;br /&gt;
Moodle&#039;s activity modules, filters, and other plugins can be activated/deactivated. If necessary, you may wish to deactivate some features (such as chat) if not required - but this isn&#039;t necessary. Some notes on the performance of certain modules:&lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;Chat&#039;&#039;&#039; module is [http://moodle.org/mod/forum/discuss.php?d=37979&amp;amp;parent=175079 said] to be a hog in terms of frequent HTTP requests to the main server. This can be reduced by setting the module to use &#039;&#039;Streamed&#039;&#039; updates, or, if you&#039;re using a Unix-based webserver, by running the chat in daemon mode. When using the Chat module use the configuration settings to tune for your expected load. Pay particular attention to the &#039;&#039;chat_old_ping&#039;&#039; and &#039;&#039;chat_refresh&#039;&#039; parameters as these can have greatest impact on server load.&lt;br /&gt;
* The &#039;&#039;&#039;Quiz&#039;&#039;&#039; module is known to stretch database performance. Try to optimise your database server by tuning. See [http://moodle.org/mod/forum/discuss.php?d=25616&amp;amp;parent=120770 for a brief report on performance for 55 students simultaneously using quizzes]&lt;br /&gt;
** See this Case Study for an extensive server stress test with 300 quiz users.[http://moodle.org/mod/forum/discuss.php?d=68579]  And this accompanying report on network traffic and server loads. [http://elearning.sgu.ac.jp/doc/PT/]&lt;br /&gt;
* The Moodle &#039;&#039;&#039;Cron&#039;&#039;&#039; task is triggered by calling the script &#039;&#039;cron.php&#039;&#039;. If this is called over HTTP (e.g. using wget or curl) it can take a large amount of memory on large installations. If it is called by directly invoking the php command (e.g. &#039;&#039;php -f /path/to/moodle/directory/admin/cron.php&#039;&#039;) efficiency can be much improved.&lt;br /&gt;
* The &#039;&#039;&#039;Recent activities&#039;&#039;&#039; block is consuming to much resources if you have huge number of records &amp;lt;code&amp;gt;mdl_log&amp;lt;/code&amp;gt;. this is being tested to optimize the SQL query.&lt;br /&gt;
&lt;br /&gt;
==Moodle Image Optimization==&lt;br /&gt;
&lt;br /&gt;
The base images delivered in the original Moodle distribution package provide unoptimized graphics, most of which can benefit from lossless recompression utilizing [http://optipng.sourceforge.net/ optipng] for PNGs, [http://www.lcdf.org/gifsicle/ gifsicle] for GIFs and [http://www.kokkonen.net/tjko/projects.html jpegoptim] for JPGs.  Optimized graphics transfer faster and provide a faster perceived response for clients[http://www.websiteoptimization.com/speed/12/], especially distance learners.  The following example will recursively optimize (without any loss of quality) all the graphics and image files included in a base Moodle installation directory on a server with the above commands installed and available.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
find /example/directory/moodle-1.9 -iname *.png -exec optipng -o7 {} \;&lt;br /&gt;
find /example/directory/moodle-1.9 -iname *.gif -exec gifsicle -O2 -b {} \;&lt;br /&gt;
find /example/directory/moodle-1.9 -iname *.jpg -exec jpegoptim -p {} \;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Both [http://optipng.sourceforge.net/ optipng] and [http://www.lcdf.org/gifsicle/ gifsicle] are provided in the base repositories of most newer Linux distributions; [http://www.kokkonen.net/tjko/projects.html jpegoptim] must be downloaded and installed manually.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[[Performance FAQ]]&lt;br /&gt;
*Using Moodle: [http://moodle.org/mod/forum/view.php?f=94 Hardware and Performance] forum&lt;br /&gt;
&lt;br /&gt;
There have been a lot of discussions on moodle.org about performance, here are some of the more interesting and (potentially) useful ones:&lt;br /&gt;
&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=83057 Performance woes!]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=57028 Performance perspectives - a little script]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=88927 Comments on planned server hardware]&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=102978#p461624 Moodle performance in a pil by Martin Langhoff]&lt;br /&gt;
[[Category:Performance]]&lt;br /&gt;
&lt;br /&gt;
[[es:Rendimiento]]&lt;br /&gt;
[[fr:Performance]]&lt;br /&gt;
[[ja:パフォーマンス]]&lt;br /&gt;
[[pl:Wydajnosc]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:lib/formslib.php_Form_Definition&amp;diff=83191</id>
		<title>Development:lib/formslib.php Form Definition</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:lib/formslib.php_Form_Definition&amp;diff=83191"/>
		<updated>2011-05-03T10:21:41Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Added note to Choosecoursefile to indicate that Moodle 2 now uses filepicker&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Formslib}}&lt;br /&gt;
== &#039;&#039;definition()&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
The definition of the elements to be included in the form, their &#039;types&#039; (PARAM_*), helpbuttons included, etc. is all included in a function you must define in your class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;definition()&#039;&#039; is used to define the elements in the form and &#039;&#039;&#039;this definition will be used for validating data submitted as well as for printing the form.&#039;&#039;&#039; For select and checkbox type elements only data that could have been selected will be allowed. And only data that corresponds to a form element in the definition will be accepted as submitted data.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;definition()&#039;&#039; should include all elements that are going to be used on form, some elements may be removed or tweaked later in &#039;&#039;definition_after_data()&#039;&#039;. Please do not create conditional elements in &#039;&#039;definition()&#039;&#039;, the definition() should not directly depend on the submitted data.&lt;br /&gt;
&lt;br /&gt;
Note that the definition function is called when the form class is instantiated. There is no option to (say) manipulate data in the class (that may affect the rendering of the form) between instantiating the form and calling any other methods. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once(&amp;quot;$CFG-&amp;gt;libdir/formslib.php&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
class simplehtml_form extends moodleform {&lt;br /&gt;
&lt;br /&gt;
    function definition() {&lt;br /&gt;
        global $CFG;&lt;br /&gt;
       &lt;br /&gt;
        $mform =&amp;amp; $this-&amp;gt;_form; // Don&#039;t forget the underscore! &lt;br /&gt;
&lt;br /&gt;
        $mform-&amp;gt;addElement()... // Add elements to your form&lt;br /&gt;
            ...&lt;br /&gt;
    }                           // Close the function&lt;br /&gt;
}                               // Close the class&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use Fieldsets to group Form Elements==&lt;br /&gt;
&lt;br /&gt;
You use code like this to open a fieldset with a &#039;&#039;legend&#039;&#039;. &amp;lt;br /&amp;gt;&lt;br /&gt;
(&#039;&#039;&#039;Note&#039;&#039;&#039;: Some themes turn off legends on admin setting pages by using CSS: &amp;lt;nowiki&amp;gt;#adminsettings legend {display:none;}&amp;lt;/nowiki&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;header&#039;, &#039;nameforyourheaderelement&#039;, get_string(&#039;titleforlegened&#039;, &#039;modulename&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can&#039;t yet nest these visible fieldsets unfortunately. But in fact groups of elements are wrapped in invisible fieldsets.&lt;br /&gt;
&lt;br /&gt;
You close a fieldset with moodle_form&#039;s closeHeaderBefore method. You tell closeHeaderBefore the element before you wish to end the fieldset. A fieldset is automatically closed if you open a new one. You need to use this code only if you want to close a fieldset and the subsequent form elements are not to be enclosed by a visible fieldset (they are still enclosed with an invisibe one with no legend) :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;closeHeaderBefore(&#039;buttonar&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==addElement==&lt;br /&gt;
&lt;br /&gt;
Use the addElement method to add an element to a form. The first few arguments are always the same. The first param is the type of the element to add. The second is the elementname to use which is normally the html name of the element in the form. The third is often the text for the label for the element.&lt;br /&gt;
&lt;br /&gt;
Some examples are below :&lt;br /&gt;
=== button ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;button&#039;, &#039;intro&#039;, get_string(&amp;quot;buttonlabel&amp;quot;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A button element. If you want a submit or cancel button see &#039;submit&#039; element.&lt;br /&gt;
&lt;br /&gt;
=== checkbox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;checkbox&#039;, &#039;ratingtime&#039;, get_string(&#039;ratingtime&#039;, &#039;forum&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a simple checkbox. The third parameter for this element is the label to display on the left side of the form. You can also supply a string as a fourth parameter to specify a label that will appear on the right of the element. Checkboxes and radio buttons can be grouped and have individual labels on their right.&lt;br /&gt;
&lt;br /&gt;
You can have a 5th parameter $attributes, as on other elements.&lt;br /&gt;
&lt;br /&gt;
==== advcheckbox ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;advcheckbox&#039;, &#039;ratingtime&#039;, get_string(&#039;ratingtime&#039;, &#039;forum&#039;), &#039;Label displayed after checkbox&#039;, array(&#039;group&#039; =&amp;gt; 1), array(0, 1));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar to the checkbox above, but with a couple of important improvements:&lt;br /&gt;
&lt;br /&gt;
# The 5th parameter is a normal $attributes array, normally used to set HTML attributes for the &amp;lt;input&amp;gt; element. However, a special value of &#039;group&#039; can be given, which will add a class name to the element, and enable its grouping for a [[Development:lib/formslib.php_add_checkbox_controller|checkbox controller]]&lt;br /&gt;
#The 6th parameter is an array of values that will be associated with the checked/unchecked state of the checkbox. With a normal checkbox you cannot choose that value, and in fact an unchecked checkbox will not even be sent with the form data.&lt;br /&gt;
&lt;br /&gt;
=== choosecoursefile ===&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;choosecoursefile&#039;, &#039;mediafile&#039;, get_string(&#039;mediafile&#039;, &#039;lesson&#039;), array(&#039;courseid&#039;=&amp;gt;$COURSE-&amp;gt;id));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose a file from the course files area. The fourth option is a list of options for the element. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note: This has been superseded by [[#filepicker|filepicker]] in Moodle 2.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
array(&#039;courseid&#039; =&amp;gt;null,  //if it is null (default then use global $COURSE&lt;br /&gt;
      &#039;height&#039;   =&amp;gt;500,   // height of the popup window&lt;br /&gt;
      &#039;width&#039;    =&amp;gt;750,   // width of the popup window&lt;br /&gt;
      &#039;options&#039;  =&amp;gt;&#039;none&#039;); //options string for the pop up window &lt;br /&gt;
                          //eg. &#039;menubar=0,location=0,scrollbars,resizable&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also pass an optional 5th parameter of attributes, as for other elements. The most useful way of using that is something like &lt;br /&gt;
&amp;lt;code php&amp;gt;array(&#039;maxlength&#039; =&amp;gt; 255, &#039;size&#039; =&amp;gt; 48)&amp;lt;/code&amp;gt;&lt;br /&gt;
to control the maxlength / size of the text box (note size will default to 48 if not specified)&lt;br /&gt;
&lt;br /&gt;
Finally, as this element is a group containing two elements (button + value), you can add validation rules by using the &#039;&#039;&#039;addGroupRule()&#039;&#039;&#039; method in this (complex) way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;$mform-&amp;gt;addGroupRule(&#039;elementname&#039;, array(&#039;value&#039; =&amp;gt; array(array(list, of, rule, params, but, fieldname))));&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where: &#039;&#039;&#039;&amp;quot;elementname&amp;quot;&#039;&#039;&#039; is the name of the choosecoursefile group element, &#039;&#039;&#039;&amp;quot;value&amp;quot;&#039;&#039;&#039; is the name of the text field within the group and the &#039;&#039;&#039;&amp;quot;list, of, addrule, params, but, fieldname&amp;quot;&#039;&#039;&#039; is exactly that, the list of fields in the normal addRule() function but ommiting the first one, the fieldname.&lt;br /&gt;
&lt;br /&gt;
For example, the [http://cvs.moodle.org/moodle/mod/resource/type/file/resource.class.php?view=markup file/url resource type], uses one &amp;quot;choosecoursefile&amp;quot; element, and it controls the maximum length of the field (255) with this use of addGroupRule():&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;$mform-&amp;gt;addGroupRule(&#039;reference&#039;, array(&#039;value&#039; =&amp;gt; array(array(get_string(&#039;maximumchars&#039;, &#039;&#039;, 255), &#039;maxlength&#039;, 255, &#039;client&#039;))));&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== date_selector ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;date_selector&#039;, &#039;assesstimefinish&#039;, get_string(&#039;to&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a date selector. You can select a Day, Month and Year using a group of select boxes. The fourth param here is an array of options. The defaults for the options are :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
array(&lt;br /&gt;
    &#039;startyear&#039; =&amp;gt; 1970, &lt;br /&gt;
    &#039;stopyear&#039;  =&amp;gt; 2020,&lt;br /&gt;
    &#039;timezone&#039;  =&amp;gt; 99, &lt;br /&gt;
    &#039;applydst&#039;  =&amp;gt; true, &lt;br /&gt;
    &#039;optional&#039;  =&amp;gt; false&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can override these defaults by supplying an array as fourth param with one or more keys with a value to override the default. You can supply a fifth param of attributes here as well.&lt;br /&gt;
&lt;br /&gt;
=== date_time_selector ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;date_time_selector&#039;, &#039;assesstimestart&#039;, get_string(&#039;from&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a group of select boxes to select a date (Day Month and Year) and time (Hour and Minute). When submitted, submitted data is processed and a timestamp is passed to $form-&amp;gt;get_data(); the fourth param here is an array of options. The defaults for the options are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
array(&lt;br /&gt;
    &#039;startyear&#039; =&amp;gt; 1970, &lt;br /&gt;
    &#039;stopyear&#039;  =&amp;gt; 2020,&lt;br /&gt;
    &#039;timezone&#039;  =&amp;gt; 99, &lt;br /&gt;
    &#039;applydst&#039;  =&amp;gt; true, &lt;br /&gt;
    &#039;step&#039;      =&amp;gt; 5&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can override these defaults by supplying an array as fourth param with one or more keys with a value to override the default. You can supply a fifth param of attributes here as well.&lt;br /&gt;
&lt;br /&gt;
===duration===&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;duration&#039;, &#039;timelimit&#039;, get_string(&#039;timelimit&#039;, &#039;quiz&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This field type lets the user input an interval of time. It comprises a text field, where you can type a number, and a dropdown for selecting a unit (days, hours, minutes or seconds). When submitted the value is converted to a number of seconds.&lt;br /&gt;
&lt;br /&gt;
You can add a fourth parameter to give options. At the moment the only option supported is here is an array of options. The defaults for the options is:&lt;br /&gt;
&amp;lt;code php&amp;gt;array(&#039;optional&#039; =&amp;gt; true)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also pass an optional 5th parameter of attributes, as for other elements. The most useful way of using that is something like &lt;br /&gt;
&amp;lt;code php&amp;gt;array(&#039;size&#039; =&amp;gt; 5)&amp;lt;/code&amp;gt;&lt;br /&gt;
to control the size of the text box.&lt;br /&gt;
&lt;br /&gt;
=== file ===&lt;br /&gt;
&lt;br /&gt;
File upload input box with browse button. In the form definition type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;file&#039;, &#039;attachment&#039;, get_string(&#039;attachment&#039;, &#039;forum&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
after form submission and validation use&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if ($data = $mform-&amp;gt;get_data()) {&lt;br /&gt;
      ...&lt;br /&gt;
    $mform-&amp;gt;save_files($destination_directory);&lt;br /&gt;
      ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need advanced settings such as required file, different max upload size or name of uploaded file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$this-&amp;gt;set_upload_manager(new upload_manager(&#039;attachment&#039;, true, false, $COURSE, false, 0, true, true, false));&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;file&#039;, &#039;attachment&#039;, get_string(&#039;attachment&#039;, &#039;forum&#039;));&lt;br /&gt;
            $mform-&amp;gt;addRule(&#039;attachment&#039;, null, &#039;required&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if ($data = $mform-&amp;gt;get_data()) {&lt;br /&gt;
      ...&lt;br /&gt;
    $mform-&amp;gt;save_files($destination_directory);&lt;br /&gt;
    $newfilename = $mform-&amp;gt;get_new_filename();&lt;br /&gt;
      ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When porting old code it is also possible to use the upload manager directly for processing of uploaded files.&lt;br /&gt;
&lt;br /&gt;
Please note that if using set_upload_manager() it must be before addElement(&#039;file&#039;,..).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
File uploading was rewritten in 2.0. Please see inline docs for now. This page will be updated when the new API stabilises.&lt;br /&gt;
&lt;br /&gt;
===filepicker===&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
General replacement of &#039;&#039;file&#039;&#039; element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;filepicker&#039;, &#039;userfile&#039;, get_string(&#039;file&#039;), null, array(&#039;maxbytes&#039; =&amp;gt; $maxbytes, &#039;accepted_types&#039; =&amp;gt; &#039;*&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
See also [[Development:Using the File API in Moodle forms]]&lt;br /&gt;
&lt;br /&gt;
=== hidden ===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;hidden&#039;, &#039;reply&#039;, &#039;yes&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A hidden element. Set the element name (in this case &#039;&#039;&#039;reply&#039;&#039;&#039;) to the stated value (in this case &#039;&#039;&#039;yes&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
=== html ===&lt;br /&gt;
You can add arbitrary HTML to your Moodle form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;html&#039;, &#039;&amp;lt;div class=&amp;quot;qheader&amp;quot;&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See [http://moodle.org/mod/forum/discuss.php?d=126935 &amp;quot;Question: Can I put a moodleform inside a table td?&amp;quot;] for a concrete example.&lt;br /&gt;
&lt;br /&gt;
=== htmleditor &amp;amp; format ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;htmleditor&#039;, &#039;text&#039;, get_string(&#039;choicetext&#039;, &#039;choice&#039;));&lt;br /&gt;
$mform-&amp;gt;setType(&#039;text&#039;, PARAM_RAW);&lt;br /&gt;
$mform-&amp;gt;addRule(&#039;text&#039;, null, &#039;required&#039;, null, &#039;client&#039;);&lt;br /&gt;
&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;format&#039;, &#039;format&#039;, get_string(&#039;format&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can supply a fourth param to htmleditor of an array of options :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&lt;br /&gt;
array(&lt;br /&gt;
    &#039;canUseHtmlEditor&#039;=&amp;gt;&#039;detect&#039;,&lt;br /&gt;
    &#039;rows&#039;  =&amp;gt; 10, &lt;br /&gt;
    &#039;cols&#039;  =&amp;gt; 65, &lt;br /&gt;
    &#039;width&#039; =&amp;gt; 0,&lt;br /&gt;
    &#039;height&#039;=&amp;gt; 0, &lt;br /&gt;
    &#039;course&#039;=&amp;gt; 0,&lt;br /&gt;
);&lt;br /&gt;
//options same as print_textarea params&lt;br /&gt;
//use rows and cols options to control htmleditor size.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===modgrade===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;modgrade&#039;, &#039;scale&#039;, get_string(&#039;grade&#039;), false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a custom element for selecting a grade for any activity module. The fourth argument is whether to include an option for no grade which has a value 0. This select box does include scales. The default is true, include no grade option.&lt;br /&gt;
&lt;br /&gt;
A helpbutton is automatically added.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===password===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         $mform-&amp;gt;addElement(&#039;password&#039;, &#039;password&#039;, get_string(&#039;label&#039;), $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A password element. Fourth param is an array or string of attributes.&lt;br /&gt;
&lt;br /&gt;
===passwordunmask===&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         $mform-&amp;gt;addElement(&#039;passwordunmask&#039;, &#039;password&#039;, get_string(&#039;label&#039;), $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A password element with option to show the password in plaintext. Fourth param is an array or string of attributes.&lt;br /&gt;
&lt;br /&gt;
=== radio ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$radioarray=array();&lt;br /&gt;
$radioarray[] = &amp;amp;MoodleQuickForm::createElement(&#039;radio&#039;, &#039;yesno&#039;, &#039;&#039;, get_string(&#039;yes&#039;), 1, $attributes);&lt;br /&gt;
$radioarray[] = &amp;amp;MoodleQuickForm::createElement(&#039;radio&#039;, &#039;yesno&#039;, &#039;&#039;, get_string(&#039;no&#039;), 0, $attributes);&lt;br /&gt;
$mform-&amp;gt;addGroup($radioarray, &#039;radioar&#039;, &#039;&#039;, array(&#039; &#039;), false);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Second param names the radio button and should be the same for each button in the group in order to toggle correctly. Third param would be the label for the form element but is generally ignored as this element will always be in a group which has it&#039;s own label. Fourth param is a string, a label to be displayed on the right of the element. The fifth is the value for this radio button. $attributes can be a string or an array of attributes.&lt;br /&gt;
&lt;br /&gt;
It is possible to add help to individual radio buttons but this requires a custom template to be defined for the group elements. See MDL-15571.&lt;br /&gt;
&lt;br /&gt;
==== setDefault ====&lt;br /&gt;
&lt;br /&gt;
To set the default for a radio button group as above use the following :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;setDefault(&#039;yesno&#039;, 0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would make the default &#039;no&#039;.&lt;br /&gt;
&lt;br /&gt;
===select===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;select&#039;, &#039;type&#039;, get_string(&#039;forumtype&#039;, &#039;forum&#039;), $FORUM_TYPES, $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The fourth param for this element is an array of options for the select box. The keys are the values for the option and the value of the array is the text for the option. The fifth param $attributes is optional, see text element for description of attributes param.&lt;br /&gt;
&lt;br /&gt;
It is also possible to create a select with certain options disabled, using [http://stackoverflow.com/questions/2138089/how-can-i-use-quickform-to-add-disabled-select-options/2150275#2150275 this technique].&lt;br /&gt;
&lt;br /&gt;
====multi-select====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $select = &amp;amp;$mform-&amp;gt;addElement(&#039;select&#039;, &#039;colors&#039;, get_string(&#039;colors&#039;), array(&#039;red&#039;, &#039;blue&#039;, &#039;green&#039;), $attributes);&lt;br /&gt;
        $select-&amp;gt;setMultiple(true);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===selectyesno===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;selectyesno&#039;, &#039;maxbytes&#039;, get_string(&#039;maxattachmentsize&#039;, &#039;forum&#039;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want a yes / no select box this one automatically translates itself and has value 1 for yes and 0 for no.&lt;br /&gt;
&lt;br /&gt;
===static===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         $mform-&amp;gt;addElement(&#039;static&#039;, &#039;description&#039;, get_string(&#039;description&#039;, &#039;exercise&#039;),&lt;br /&gt;
                  get_string(&#039;descriptionofexercise&#039;, &#039;exercise&#039;, $COURSE-&amp;gt;students));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a static element. It should be used with care if it is used to display a static piece of text with a label. The third param is the label and the fourth is the static text itself.&lt;br /&gt;
&lt;br /&gt;
===submit, reset and cancel===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        //normally you use add_action_buttons instead of this code&lt;br /&gt;
        $buttonarray=array();&lt;br /&gt;
        $buttonarray[] = &amp;amp;$mform-&amp;gt;createElement(&#039;submit&#039;, &#039;submitbutton&#039;, get_string(&#039;savechanges&#039;));&lt;br /&gt;
        $buttonarray[] = &amp;amp;$mform-&amp;gt;createElement(&#039;reset&#039;, &#039;resetbutton&#039;, get_string(&#039;revert&#039;));&lt;br /&gt;
        $buttonarray[] = &amp;amp;$mform-&amp;gt;createElement(&#039;cancel&#039;);&lt;br /&gt;
        $mform-&amp;gt;addGroup($buttonarray, &#039;buttonar&#039;, &#039;&#039;, array(&#039; &#039;), false);&lt;br /&gt;
        $mform-&amp;gt;closeHeaderBefore(&#039;buttonar&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;Submit&#039; type element is a submit type form element which will submit the form. A &#039;Reset&#039; will not submit the form but will reset any changes the user has made to form contents. A &#039;Cancel&#039; element cancels form submission. You need to have a branch in your code before you check for get_data() to check if submission has been cancelled with is_cancelled(); See the example on the usage page.&lt;br /&gt;
&lt;br /&gt;
You should name your submit and reset buttons &#039;submitbutton&#039; and &#039;resetbutton&#039; or something similar (not &#039;submit&#039; and &#039;reset&#039;). This avoids problems in JavaScript of collisions between form element names and names of JavaScript methods of the form object.&lt;br /&gt;
&lt;br /&gt;
====add_action_buttons($cancel = true, $submitlabel=null);====&lt;br /&gt;
&lt;br /&gt;
You will normally use this helper function which is a method of moodleform to add all the &#039;action&#039; buttons to the end of your form. A boolean parameter allow you to specify whether to include a cancel button and specify the label for your submit button (pass the result of get_string). Default for the submit button label is get_string(&#039;savechanges&#039;).&lt;br /&gt;
&lt;br /&gt;
===text===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;text&#039;, &#039;name&#039;, get_string(&#039;forumname&#039;, &#039;forum&#039;), $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For a simple text element. Your fourth parameter here can be a string or array of attributes for the text element. The following are equivalent :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $attributes=&#039;size=&amp;quot;20&amp;quot;&#039;;&lt;br /&gt;
        $attributes=array(&#039;size&#039;=&amp;gt;&#039;20&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Generally you are encouraged to use CSS instead of using attributes for styling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A format element can be used as a format select box. It will be non-selectable if you&#039;re using an html editor.&lt;br /&gt;
&lt;br /&gt;
The third param for this element is $useHtmlEditor and it defaults to null in which case an html editor is used if the browser and user profile support it.&lt;br /&gt;
&lt;br /&gt;
===textarea===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;textarea&#039;, &#039;introduction&#039;, get_string(&amp;quot;introtext&amp;quot;, &amp;quot;survey&amp;quot;), &#039;wrap=&amp;quot;virtual&amp;quot; rows=&amp;quot;20&amp;quot; cols=&amp;quot;50&amp;quot;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A textarea element. If you want an htmleditor use htmleditor element. Fourth element here is a string or array of attributes.&lt;br /&gt;
&lt;br /&gt;
===recaptcha===&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;recaptcha&#039;, &#039;recaptcha_field_name&#039;, $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use this recaptcha element to reduce the spam risk in your forms. Third element here is a string or array of attributes. Take care to get an API key from http://recaptcha.net/api/getkey before using this element.&lt;br /&gt;
&lt;br /&gt;
To check whether recaptcha is enabled at site level use:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (!empty($CFG-&amp;gt;recaptchapublickey) &amp;amp;&amp;amp; !empty($CFG-&amp;gt;recaptchaprivatekey)) {&lt;br /&gt;
    //recaptcha is enabled&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tags===&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;tags&#039;, &#039;field_name&#039;, $lable, $options, $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Used for editing a list of tags, for example on a blog post.&lt;br /&gt;
&lt;br /&gt;
There is only one option available, &#039;display&#039;, which should be set to one of the contstants MoodleQuickForm_tags::ONLYOFFICIAL, NOOFFICIAL or DEFAULTUI. This controls whether the official tags are listed for easy selection, or a text area where arbitrary tags may be typed, or both. The default is both.&lt;br /&gt;
&lt;br /&gt;
The value should be set/returned as an array of tags.&lt;br /&gt;
&lt;br /&gt;
==addGroup==&lt;br /&gt;
&lt;br /&gt;
A &#039;group&#039; in formslib is just a group of elements that will have a label and will be included on one line. &lt;br /&gt;
&lt;br /&gt;
For example typical code to include a submit and cancel button on the same line : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $buttonarray=array();&lt;br /&gt;
        $buttonarray[] =&amp;amp; $mform-&amp;gt;createElement(&#039;submit&#039;, &#039;submitbutton&#039;, get_string(&#039;savechanges&#039;));&lt;br /&gt;
        $buttonarray[] =&amp;amp; $mform-&amp;gt;createElement(&#039;submit&#039;, &#039;cancel&#039;, get_string(&#039;cancel&#039;));&lt;br /&gt;
        $mform-&amp;gt;addGroup($buttonarray, &#039;buttonar&#039;, &#039;&#039;, array(&#039; &#039;), false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You use the same arguments for createElement as you do for addElement. Any label for the element in the third argument is normally ignored (but not in the case of the submit buttons above where the third argument is not for a label but is the text for the button).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a bad example (don&#039;t do this for real, use the &#039;optional&#039; =&amp;gt; true option of the date element): putting a date_selector (which is itself a group of elements) and a checkbox on the same line, note that you can disable every element in the group using the group name &#039;availablefromgroup&#039; but it doesn&#039;t disable the controlling element the &#039;availablefromenabled&#039; checkbox:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $availablefromgroup=array();&lt;br /&gt;
	$availablefromgroup[] =&amp;amp; $mform-&amp;gt;createElement(&#039;date_selector&#039;, &#039;availablefrom&#039;, &#039;&#039;);&lt;br /&gt;
	$availablefromgroup[] =&amp;amp; $mform-&amp;gt;createElement(&#039;checkbox&#039;, &#039;availablefromenabled&#039;, &#039;&#039;, get_string(&#039;enable&#039;));&lt;br /&gt;
        $mform-&amp;gt;addGroup($availablefromgroup, &#039;availablefromgroup&#039;, get_string(&#039;availablefromdate&#039;, &#039;data&#039;), &#039;&amp;amp;nbsp;&#039;, false);&lt;br /&gt;
        $mform-&amp;gt;disabledIf(&#039;availablefromgroup&#039;, &#039;availablefromenabled&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==addRule==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addRule(&#039;elementname&#039;, get_string(&#039;error&#039;), &#039;rule type&#039;, &#039;extraruledata&#039;, &#039;server&#039;(default), false, false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first param(element) is an element name and second(message) is the error message that will be displayed to the user.&lt;br /&gt;
The third parameter(type) is the type of rule. The fourth param(format) is used for extra data needed with some rules such as minlength and regex. The fifth parameter(validation) validates input data on server or client side, if validation is done on client side then it will be checked on the server side as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * @param    string     $element       Form element name&lt;br /&gt;
 * @param    string     $message       Message to display for invalid data&lt;br /&gt;
 * @param    string     $type          Rule type, use getRegisteredRules() to get types&lt;br /&gt;
 * @param    string     $format        (optional)Required for extra rule data&lt;br /&gt;
 * @param    string     $validation    (optional)Where to perform validation: &amp;quot;server&amp;quot;, &amp;quot;client&amp;quot;&lt;br /&gt;
 * @param    boolean    $reset         Client-side validation: reset the form element to its original value if there is an error?&lt;br /&gt;
 * @param    boolean    $force         Force the rule to be applied, even if the target form element does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Common Rule Types&#039;&#039;&#039;&lt;br /&gt;
* required &lt;br /&gt;
* maxlength&lt;br /&gt;
* minlength&lt;br /&gt;
* rangelength&lt;br /&gt;
* email&lt;br /&gt;
* regex&lt;br /&gt;
* lettersonly&lt;br /&gt;
* alphanumeric&lt;br /&gt;
* numeric&lt;br /&gt;
* nopunctuation&lt;br /&gt;
* nonzero&lt;br /&gt;
* callback&lt;br /&gt;
* compare&lt;br /&gt;
&lt;br /&gt;
==setHelpButton==&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;setHelpButton(&#039;lessondefault&#039;, array(&#039;lessondefault&#039;, get_string(&#039;lessondefault&#039;, &#039;lesson&#039;), &#039;lesson&#039;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First param is an elementname and the second param is an array of params that are passed to helpbutton in weblib.php. Params are :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * @param string $page  The keyword that defines a help page&lt;br /&gt;
 * @param string $title The title of links, rollover tips, alt tags etc&lt;br /&gt;
 *           &#039;Help with&#039; (or the language equivalent) will be prefixed and &#039;...&#039; will be stripped.&lt;br /&gt;
 * @param string $module Which module is the page defined in&lt;br /&gt;
 * @param mixed $image Use a help image for the link?  (true/false/&amp;quot;both&amp;quot;)&lt;br /&gt;
 * @param boolean $linktext If true, display the title next to the help icon.&lt;br /&gt;
 * @param string $text If defined then this text is used in the page, and&lt;br /&gt;
 *           the $page variable is ignored.&lt;br /&gt;
 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.&lt;br /&gt;
 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Make sure you don&#039;t set boolean $return to false. &lt;br /&gt;
&lt;br /&gt;
You need to do use this method after addElement();&lt;br /&gt;
&lt;br /&gt;
==addHelpButton==&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addHelpButton(&#039;api_key_field&#039;, &#039;api_key&#039;, &#039;block_extsearch&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Moodle 2.0 the &amp;quot;setHelpButton&amp;quot; method has been deprecated in favor of the &amp;quot;addHelpButton&amp;quot; method, which has a simplified interface and uses $OUTPUT-&amp;gt;help_icon() on the back end. The following parameters are expected:&lt;br /&gt;
&lt;br /&gt;
 * @param $elementname The name of the form element to add the help button for&lt;br /&gt;
 * @param $identifier The identifier for the help string and its title (see below)&lt;br /&gt;
 * @param $component The component name to look for the help string in&lt;br /&gt;
&lt;br /&gt;
Unlike in Moodle 1.9, it is no longer necessary to put your help pages in separate HTML files. Instead, the function looks for two strings:&lt;br /&gt;
&lt;br /&gt;
 1. get_string($identifier, $component): The title of the help page&lt;br /&gt;
 2. get_string(&amp;quot;{$identifier}_help&amp;quot;, $component): The content of the help page&lt;br /&gt;
&lt;br /&gt;
So you will need to have &#039;&#039;&#039;$identifier&#039;&#039;&#039; and &#039;&#039;&#039;{$identifier}_help&#039;&#039;&#039; defined in order for the help button to be created properly.&lt;br /&gt;
&lt;br /&gt;
==setDefault==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;select&#039;, &#039;grade&#039;, get_string(&#039;gradeforsubmission&#039;, &#039;exercise&#039;), $grades);&lt;br /&gt;
        $mform-&amp;gt;setHelpButton(&#039;grade&#039;, array(&#039;grade&#039;, get_string(&#039;gradeforsubmission&#039;, &#039;exercise&#039;), &#039;exercise&#039;));&lt;br /&gt;
        $mform-&amp;gt;setDefault(&#039;grade&#039;, 100);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the default of the form value with setDefault($elementname, $value); where elementname is the elementname whose default you want to set and $value is the default to set. We set the defaults for the form in definition(). This default is what is used if no data is loaded into the form with set_data(); eg. on display of the form for an &#039;add&#039; rather than &#039;update&#039; function.&lt;br /&gt;
&lt;br /&gt;
==disabledIf==&lt;br /&gt;
&lt;br /&gt;
For any element or groups of element in a form you can conditionally disable the group or individual element depending on conditions.&lt;br /&gt;
&lt;br /&gt;
You can use $mform-&amp;gt;disabledIf($elementName, $dependentOn, $condition = &#039;notchecked&#039;, $value=null)&lt;br /&gt;
&lt;br /&gt;
* elementname can be a group. If you specify a group all elements in the group will be disabled (if dependentOn is in elementname group that is ignored and not disabled). These are the element names you&#039;ve used as the second argument in addElement or addGroup.&lt;br /&gt;
* dependentOn is the actual name of the element as it will appear in html. This can be different to the name used in addGroup particularly but also addElement where you&#039;re adding a complex element like a date_selector. Check the html of your page. You typically make the depedentOn a checkbox or select box.&lt;br /&gt;
* $condition will be &#039;notchecked&#039;, &#039;checked&#039;, &#039;noitemselected&#039;, &#039;eq&#039; or, if it is anything else, we test for &#039;neq&#039;.&lt;br /&gt;
** If $condition is &#039;eq&#039; or &#039;neq&#039; then we check the value of the dependentOn field and check for equality (==) or nonequality (!=) in js&lt;br /&gt;
** If $condition is &#039;checked&#039; or &#039;notchecked&#039; then we check to see if a checkbox is checked or not.&lt;br /&gt;
** If $condition is &#039;noitemselected&#039; then we check to see whether nothing is selected in a dropdown list.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
 // Disable my control unless a checkbox is checked.&lt;br /&gt;
 $mform-&amp;gt;disabledIf(&#039;mycontrol&#039;, &#039;somecheckbox&#039;);&lt;br /&gt;
 &lt;br /&gt;
 // Disable my control if a checkbox &#039;&#039;&#039;is&#039;&#039;&#039; checked.&lt;br /&gt;
 $mform-&amp;gt;disabledIf(&#039;mycontrol&#039;, &#039;somecheckbox&#039;, &#039;checked&#039;);&lt;br /&gt;
 &lt;br /&gt;
 // Disable my control unless a dropdown has value 42.&lt;br /&gt;
 $mform-&amp;gt;disabledIf(&#039;mycontrol&#039;, &#039;someselect&#039;, &#039;eq&#039;, 42);&lt;br /&gt;
&lt;br /&gt;
The possible choices here are in the function lockoptionsall in lib/javascript-static.js.&lt;br /&gt;
&lt;br /&gt;
==setType==&lt;br /&gt;
&lt;br /&gt;
PARAM_* types are used to specify how a submitted variable should be cleaned. These should be used for get parameters such as id, course etc. which are used to load a page and also with setType(); method. Every form element should have a type specified except select, radio box and checkbox elements, these elements do a good job of cleaning themselves (only specified options are allowed as user input).&lt;br /&gt;
&lt;br /&gt;
===Most Commonly Used PARAM_* Types===&lt;br /&gt;
&lt;br /&gt;
These are the most commonly used PARAM_* types and their proper uses. More types can be seen in moodlelib.php starting around line 100.&lt;br /&gt;
&lt;br /&gt;
* PARAM_CLEAN is deprecated and you should try to use a more specific type.&lt;br /&gt;
* PARAM_TEXT should be used for cleaning data that is expected to be plain text. It will strip all html tags. But will still let tags for multilang support through.&lt;br /&gt;
* PARAM_NOTAGS should be used for cleaning data that is expected to be plain text. It will strip *all* html type tags. It will still *not* let tags for multilang support through. This should be used for instance for email addresses where no multilang support is appropriate.&lt;br /&gt;
* PARAM_RAW means no cleaning whatsoever, it is used mostly for data from the html editor. Data from the editor is later cleaned before display using format_text() function. PARAM_RAW can also be used for data that is validated by some other way or printed by p() or s().&lt;br /&gt;
* PARAM_INT should be used for integers.&lt;br /&gt;
* PARAM_ACTION is an alias of PARAM_ALPHA and is used for hidden fields specifying form actions.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://www.midnighthax.com/quickform.php PEAR HTML QuickForm Getting Started Guide] by Keith Edmunds of Midnighthax.com&lt;br /&gt;
* [http://pear.php.net/manual/en/package.html.html-quickform.php PEAR::HTML_QuickForm manual]&lt;br /&gt;
&lt;br /&gt;
[[Category:Formslib]]&lt;br /&gt;
&lt;br /&gt;
If you have problems creating php forms you may get them with form builder http://phpforms.net/tutorial/html-basics/form-builder.html&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:Subplugins&amp;diff=82199</id>
		<title>Development:Subplugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:Subplugins&amp;diff=82199"/>
		<updated>2011-03-23T13:45:52Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Fixed transposed parameters in example.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sub plugins allow activity modules to be extended without having to change the module&#039;s code.&lt;br /&gt;
&lt;br /&gt;
Each activity module can define a set of subplugin types in &amp;lt;tt&amp;gt;db/subplugins.php&amp;lt;/tt&amp;gt;.  The file must contain an array called &amp;lt;tt&amp;gt;$subplugins&amp;lt;/tt&amp;gt;, with the plugin type as the key for the directory containing the plugins. For example, from &amp;lt;tt&amp;gt;mod/workshop/db/subplugins.php&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 $subplugins = array(&lt;br /&gt;
                    &#039;workshopform&#039;       =&amp;gt; &#039;mod/workshop/form&#039;,&lt;br /&gt;
                    &#039;workshopallocation&#039; =&amp;gt; &#039;mod/workshop/allocation&#039;,&lt;br /&gt;
                    &#039;workshopeval&#039;       =&amp;gt; &#039;mod/workshop/eval&#039;,&lt;br /&gt;
                    );&lt;br /&gt;
This defines 3 plugin types, &amp;lt;tt&amp;gt;workshopform&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;workshopallocation&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;workshopeval&amp;lt;/tt&amp;gt;. The plugins themselves can be found in &amp;lt;tt&amp;gt;mod/workshop/form&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;mod/workshop/allocation&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mod/workshop/eval&amp;lt;/tt&amp;gt;, respectively.  Each of these directories can contain a number of plugins, each within it&#039;s own subdirectory.&lt;br /&gt;
&lt;br /&gt;
=== Writing a sub-plugin ===&lt;br /&gt;
A sub-plugin has the same structure as a regular plugin.  It will have a &amp;lt;tt&amp;gt;version.php&amp;lt;/tt&amp;gt;, a &amp;lt;tt&amp;gt;lang&amp;lt;/tt&amp;gt; directory, and can have a &amp;lt;tt&amp;gt;db&amp;lt;/tt&amp;gt; directory with an &amp;lt;tt&amp;gt;install.xml&amp;lt;/tt&amp;gt; and all the other hooks you&#039;d expect to see used in any other type of plugin, such as an activity, block, or admin report.&lt;br /&gt;
&lt;br /&gt;
An important thing to remember when using lang strings is to prefix the component with the plugin type, as you do with all non-activity blocks.  So to print the name of the &amp;quot;accumulative&amp;quot; workshopform plugin, you&#039;d do&lt;br /&gt;
 print_string(&#039;pluginname&#039;, &#039;workshopform_accumulative&#039;);&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:Subplugins&amp;diff=82198</id>
		<title>Development:Subplugins</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:Subplugins&amp;diff=82198"/>
		<updated>2011-03-23T13:45:07Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: New page: Sub plugins allow activity modules to be extended without having to change the module&amp;#039;s code.  Each activity module can define a set of subplugin types in &amp;lt;tt&amp;gt;db/subplugins.php&amp;lt;/tt&amp;gt;.  The ...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Sub plugins allow activity modules to be extended without having to change the module&#039;s code.&lt;br /&gt;
&lt;br /&gt;
Each activity module can define a set of subplugin types in &amp;lt;tt&amp;gt;db/subplugins.php&amp;lt;/tt&amp;gt;.  The file must contain an array called &amp;lt;tt&amp;gt;$subplugins&amp;lt;/tt&amp;gt;, with the plugin type as the key for the directory containing the plugins. For example, from &amp;lt;tt&amp;gt;mod/workshop/db/subplugins.php&amp;lt;/tt&amp;gt;:&lt;br /&gt;
 $subplugins = array(&lt;br /&gt;
                    &#039;workshopform&#039;       =&amp;gt; &#039;mod/workshop/form&#039;,&lt;br /&gt;
                    &#039;workshopallocation&#039; =&amp;gt; &#039;mod/workshop/allocation&#039;,&lt;br /&gt;
                    &#039;workshopeval&#039;       =&amp;gt; &#039;mod/workshop/eval&#039;,&lt;br /&gt;
                    );&lt;br /&gt;
This defines 3 plugin types, &amp;lt;tt&amp;gt;workshopform&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;workshopallocation&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;workshopeval&amp;lt;/tt&amp;gt;. The plugins themselves can be found in &amp;lt;tt&amp;gt;mod/workshop/form&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;mod/workshop/allocation&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;mod/workshop/eval&amp;lt;/tt&amp;gt;, respectively.  Each of these directories can contain a number of plugins, each within it&#039;s own subdirectory.&lt;br /&gt;
&lt;br /&gt;
=== Writing a sub-plugin ===&lt;br /&gt;
A sub-plugin has the same structure as a regular plugin.  It will have a &amp;lt;tt&amp;gt;version.php&amp;lt;/tt&amp;gt;, a &amp;lt;tt&amp;gt;lang&amp;lt;/tt&amp;gt; directory, and can have a &amp;lt;tt&amp;gt;db&amp;lt;/tt&amp;gt; directory with an &amp;lt;tt&amp;gt;install.xml&amp;lt;/tt&amp;gt; and all the other hooks you&#039;d expect to see used in any other type of plugin, such as an activity, block, or admin report.&lt;br /&gt;
&lt;br /&gt;
An important thing to remember when using lang strings is to prefix the component with the plugin type, as you do with all non-activity blocks.  So to print the name of the &amp;quot;accumulative&amp;quot; workshopform plugin, you&#039;d do&lt;br /&gt;
 print_string(&#039;workshopform_accumulative&#039;, &#039;pluginname&#039;);&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:Developer_documentation&amp;diff=82197</id>
		<title>Development:Developer documentation</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:Developer_documentation&amp;diff=82197"/>
		<updated>2011-03-23T13:34:41Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* Make a new plugin */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[image:moodle-development-logo.jpg|right|400px]]&lt;br /&gt;
&lt;br /&gt;
This [[:Category:Developer|Developer]] section of Moodle Docs is aimed at developers who contribute to the Moodle code, plugins, themes, and so on.&lt;br /&gt;
&lt;br /&gt;
* If you manage a Moodle site, [[Administrator documentation]] may suit your needs better. &lt;br /&gt;
* If you teach using Moodle, try [[Teacher documentation]].&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; New developer documentation pages should be added to the &#039;&#039;Development namespace&#039;&#039; by typing &amp;lt;code&amp;gt;Development:&amp;lt;/code&amp;gt; before the new page name i.e. &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[Development:New page name]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;. If you are a developer, you probably want to change your [[Special:Preferences|preferences]] to include the Development namespace in searches.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A page may be added to the Developer category by adding the template &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{CategoryDeveloper}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to the bottom of the page. - If required, you can use &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[Category:Developer|Sort key]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to provide a sort key other than the default page name.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How Moodle development works==&lt;br /&gt;
&lt;br /&gt;
The [[Development:Overview|overview of the Moodle development process]] explains how Moodle development occurs and how people become Moodle developers. Current plans are listed on the [[Roadmap]].&lt;br /&gt;
&lt;br /&gt;
You can also enrol in one of the [http://dev.moodle.org Moodle Developer Courses].&lt;br /&gt;
&lt;br /&gt;
==Guidelines==&lt;br /&gt;
&lt;br /&gt;
The following guidelines are crucial reading for anyone wanting to contribute to the Moodle code base:&lt;br /&gt;
*[[Development:Coding|Coding guidelines]] have to be followed by all Moodle developers&lt;br /&gt;
*[[Moodle architecture]] gives an overview of how the Moodle code works&lt;br /&gt;
*[[Development:Process]] explains how changes are incorporated into Moodle&lt;br /&gt;
*[[Tracker]] explains the Moodle Tracker for keeping track of bugs, issues, feature requests etc&lt;br /&gt;
*[[Development:Working with the Community|Working with the Community]] explains how to engage with the dev community and discuss changes&lt;br /&gt;
*[[Development:Unit tests|Unit tests]] explains how to run the unit tests, and how to write new test cases.&lt;br /&gt;
*[[Development:Profiling PHP|Profiling PHP]] how to analyse your code to find out why it is slow.&lt;br /&gt;
*[[Development:Fast portable SQL]] shows SQL techniques that are fast, efficient, and known to work on all supported DBs.&lt;br /&gt;
*[[Development:Development hints and tips]] a (developing) list of general wisdom to help with your Moodle projects.&lt;br /&gt;
&lt;br /&gt;
==Documentation for core components==&lt;br /&gt;
&lt;br /&gt;
This section is for documentation of specific components of the existing core Moodle code. Discussion of components that are under discussion or in development can be found in the [[Development:Developer notes|developer notes]] or on the [[Roadmap|roadmap]].&lt;br /&gt;
&lt;br /&gt;
The documents below give a general overview. For detailed function-by-function documentation, see the [http://phpdocs.moodle.org/ phpDocumentor] documentation that is automatically generated from the comments in the code. &lt;br /&gt;
&lt;br /&gt;
And don&#039;t forget that the most up-to-date and detailed description of how the code works is the code itself, and you can [http://xref.moodle.org/nav.html?index.html browse the code online] using [[Development:PHPXref|PHPXref]].&lt;br /&gt;
&lt;br /&gt;
===Core components ===&lt;br /&gt;
&lt;br /&gt;
*[[Development:XMLDB_Documentation|Database abstraction layer]] @ v[[1.7]]&lt;br /&gt;
*[[Development:Roles|Roles and Capabilities system]] @ v[[1.7]] for controlling who can do what&lt;br /&gt;
*[[Development:lib/formslib.php|Forms library]] @ v[[1.8]] for creating accessible and secure HTML forms that let users edit things&lt;br /&gt;
*[[Development:Using_the_file_API|File API]] @ v[[2.0]] for managing files stored by Moodle&lt;br /&gt;
*[[Development:Database schema introduction|The database schema]]&lt;br /&gt;
*[[Development:What happens when you require config.php|What happens when you require config.php]]&lt;br /&gt;
*[[Development:lib/moodlelib.php|lib/moodlelib.php]]&lt;br /&gt;
*[[Development:lib/weblib.php|lib/weblib.php]] for outputting stuff&lt;br /&gt;
&lt;br /&gt;
===Core libraries with a more specific uses===&lt;br /&gt;
&lt;br /&gt;
*[[Authentication API]]&lt;br /&gt;
*[[Cookieless Sessions]]&lt;br /&gt;
*[[Email processing]]&lt;br /&gt;
*[[Development:Environment checking|Environment checking]] before install, check the user&#039;s server to ensure Moodle will work there.&lt;br /&gt;
*[[Development:Groups|Groups system]]&lt;br /&gt;
*[[Development:Grades|Gradebook]]&lt;br /&gt;
*[[Development:Moodle Network|Moodle Network]]&lt;br /&gt;
*[[Question engine]]&lt;br /&gt;
*[[Stats package]]&lt;br /&gt;
*[[UTF-8 migration|Migration to UTF-8]] @ v[[:Category:Moodle 1.6|1.6]]&lt;br /&gt;
*[http://developer.yahoo.com/yui YUI JavaScript library] - YUI was selected as the official AJAX library for Moodle.&lt;br /&gt;
*[[Development:lib/graphlib|lib/graphlib]]&lt;br /&gt;
*[[Development:Admin settings|Admin settings]]&lt;br /&gt;
&lt;br /&gt;
===Modules included in the standard distribution===&lt;br /&gt;
&lt;br /&gt;
*[[Development:Lesson Specification|Lesson Specification]]&lt;br /&gt;
*[[Quiz developer docs|Quiz module]]&lt;br /&gt;
*[[SCORM schema|SCORM module 1.5 schema]]&lt;br /&gt;
&lt;br /&gt;
==How you can contribute==&lt;br /&gt;
&lt;br /&gt;
===Make a new plugin===&lt;br /&gt;
&lt;br /&gt;
The M in Moodle stands for modular, and the easiest, most maintainable way to add new functionality to Moodle is by using one of the many plugin APIs. There are many types of plugin you can write:&lt;br /&gt;
*[[Development:Modules|Activity modules]], see also [[Development:NEWMODULE Documentation]] (work in progress)&lt;br /&gt;
**and [[Development:Subplugins|Sub-Plugins]] (2.0 Onwards)&lt;br /&gt;
*[[Development:Admin reports|Admin reports]]&lt;br /&gt;
*[[Development:Assignment types|Assignment types]]&lt;br /&gt;
*[[Development:Authentication plugins|Authentication plugins]]&lt;br /&gt;
*[[Development:Blocks|Blocks]]&lt;br /&gt;
*Content editors (2.0 onwards)&lt;br /&gt;
*[[Course formats]]&lt;br /&gt;
*[[Development:Course Report Plugins|Course reports]]&lt;br /&gt;
*Course importers (2.0 onwards)&lt;br /&gt;
*[[Development:Database fields|Database fields]]&lt;br /&gt;
*[[Development:Database presets|Database presets]]&lt;br /&gt;
*[[Development:Enrolment plugins|Enrolment plugins]]&lt;br /&gt;
*[[Development:Filters|Filters]]&lt;br /&gt;
*[[Development:Gradebook_Report_Tutorial|Gradebook report]]&lt;br /&gt;
*[[Development:Gradebook export|Gradebook export]]&lt;br /&gt;
*[[Development:Gradebook import|Gradebook import]]&lt;br /&gt;
*Message senders (2.0 onwards)&lt;br /&gt;
*Mnet services&lt;br /&gt;
*Plagiarism detection plugins (2.0 onwards)&lt;br /&gt;
*[[Development:Writing_a_Portfolio_Plugin|Portfolio plugins]] (2.0 onwards)&lt;br /&gt;
*[[Development:Question_type_plugin_how_to|Question types]]&lt;br /&gt;
*[[Development:Question import/export formats|Question import/export formats]]&lt;br /&gt;
*[[Development:How to write a quiz report plugin|Quiz reports]]&lt;br /&gt;
*[[Development:Repository plugins|Repository plugins]] (2.0 onwards)&lt;br /&gt;
*[[Development:Resource types|Resource types]]&lt;br /&gt;
*[[Development:Search engine adapters|Search engine adapters]]&lt;br /&gt;
*Themes which are different in [[Development:Themes_2.0|Moodle 2.0]], and [[Theme_basics|earlier versions]].&lt;br /&gt;
*User profile fields&lt;br /&gt;
*[[Development:Web services (2.0 onwards)|Web services (2.0 onwards)]]&lt;br /&gt;
*Workshop allocators (2.0 onwards)&lt;br /&gt;
*Workshop forms (2.0 onwards)&lt;br /&gt;
*Workshop evaluators (2.0 onwards)&lt;br /&gt;
&lt;br /&gt;
General information that applies to all types of plugins&lt;br /&gt;
*[[Development:Places to search for lang strings|Where to put language strings for your plugin]]&lt;br /&gt;
*[[Development:Installing and upgrading plugin database tables|Defining the database tables for your plugin]]&lt;br /&gt;
&lt;br /&gt;
Please see the [[Development:Guidelines for contributed code|Guidelines for contributed code]] for an overview of how to contribute to the Moodle code.&lt;br /&gt;
&lt;br /&gt;
Sometimes it is not possible to write a proper plugin for what you want to do, in which case you may have to resort to using the [[Development:Local_customisation|local customisations]] hook.&lt;br /&gt;
&lt;br /&gt;
===Change core code===&lt;br /&gt;
&lt;br /&gt;
Some types of change can only be made by editing the core Moodle code. Such changes are much harder to maintain than plugins. If you want your core change to be considered for inclusion in the official Moodle release, you need to create an issue in the [[Tracker|tracker]], and attach your change as a [[Development:How_to_create_a_patch|patch]]. It is also a good idea to discuss your ideas in the forums first.  See [[Development:Overview#Major_Development]] for more details.&lt;br /&gt;
&lt;br /&gt;
===Ways to contribute that do not involve PHP programming===&lt;br /&gt;
&lt;br /&gt;
*[[Themes|Create Moodle themes]]&lt;br /&gt;
*[[Translation|Translate Moodle into other languages]]&lt;br /&gt;
*[[MoodleDocs:Guidelines for contributors|Help document Moodle]]&lt;br /&gt;
*[[Development:Tests|Join the testing effort]], which involves [[Tracker|participating in the bug tracker]]&lt;br /&gt;
&lt;br /&gt;
==Plans for the future==&lt;br /&gt;
&lt;br /&gt;
Ideas for and details of planned future features of Moodle are initially discussed on the forums in the [http://moodle.org/course/view.php?id=5 Using Moodle] course at moodle.org. That developer discussions are intermixed with user discussions in the same forums may seem strange at first but is one of the reasons for the success of Moodle. It is important that both end-users and developers discuss the future features together.&lt;br /&gt;
&lt;br /&gt;
Once ideas begin to crystallize on the forums they can be summarized in this wiki, either as part of the [[Roadmap|roadmap]] or in the form of [[Development:Developer notes|developer notes]]. These pages then form the basis for further discussion in the forums.&lt;br /&gt;
&lt;br /&gt;
*[[Roadmap]]&lt;br /&gt;
*[[Development:Developer notes|Developer notes]]&lt;br /&gt;
*[[Student projects]]&lt;br /&gt;
*[[Developer meetings]]&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
*[[Developer FAQ]] - frequently asked questions, especially useful for newcomers to Moodle&lt;br /&gt;
*[[Development:Finding_your_way_into_the_Moodle_code|Finding your way into the Moodle code]] - also aimed at newcomers&lt;br /&gt;
*[http://tracker.moodle.org/ Moodle tracker] - bug reports, feature requests and other tracked issues&lt;br /&gt;
**[[Firefox tracker search]] - How to setup a firefox quicksearch to easily navigate to moodle bugs&lt;br /&gt;
**[[Firefox tracker search#Firefox Search Plugins|Firefox Search Plugins]] - Find tracked issues even more easily&lt;br /&gt;
*[[Unmerged files]] - changes on the stable branch in CVS that have not been merged to [[HEAD]]&lt;br /&gt;
*Browse the code online:&lt;br /&gt;
**[http://cvs.moodle.org/moodle/ the code with a complete change history from CVS]&lt;br /&gt;
**[http://xref.moodle.org/index.html the code, with links generated by PHPXref]&lt;br /&gt;
*[http://phpdocs.moodle.org/ Moodle PHP doc reference] - compiled nightly from the comment attached to each class and function in the code.  &lt;br /&gt;
*[[Development:Database Schema|Database Schema]] - for recent releases&lt;br /&gt;
*[http://moodle.org/course/view.php?id=5#4 Development news and discussion] section of Using Moodle course&lt;br /&gt;
**especially the [http://moodle.org/mod/forum/view.php?id=55 General developer forum]&lt;br /&gt;
**[[Filters used on the Moodle.org forums|cool tricks you can use in the moodle.org forums]]&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
Some tools people use when working on Moodle code:&lt;br /&gt;
&lt;br /&gt;
=== IDEs ===&lt;br /&gt;
&lt;br /&gt;
* [[Development:Setting_up_Netbeans|Setting up NetBeans for Moodle development]] - NetBeans for PHP is a great out-of-the-box editor.&lt;br /&gt;
* [[Development:Setting_up_Eclipse|Setting up Eclipse for Moodle development]] - Eclipse is a great editor to use for php development, if you can work out how to set it up.&lt;br /&gt;
* [[Development:vim|Setting up Vim for Moodle development]]&lt;br /&gt;
* [http://www.aptana.com/ Aptana Studio 2]&lt;br /&gt;
&lt;br /&gt;
=== Browser add-ons ===&lt;br /&gt;
*[http://getfirebug.com Firebug], see [[Firebug]] for details.&lt;br /&gt;
* [[Web developer extension]]&lt;br /&gt;
* [https://addons.mozilla.org/en-US/firefox/addon/394 ViewSourceWith] - The main goal is to view page source with external applications, but you can do a lot of other things as well.&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous === &lt;br /&gt;
*[[Development:ctags|Ctags]] - Using a tags file to navigate code&lt;br /&gt;
*[[W3C_validation|W3C HTML validator]] - Moodle has built in support to make using it easier.&lt;br /&gt;
*[[Development:Windows Installer|Windows Installer]] - Windows Installer documentation for developer.&lt;br /&gt;
&lt;br /&gt;
See also: [http://dev.moodle.org/mod/forum/view.php?id=18 Useful Development Tools forum]in the [http://dev.moodle.org/course/view.php?id=2 Introduction to Moodle Programming course]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/security/ Moodle Security Announcements]&lt;br /&gt;
*[http://moodle.com/partners/ Moodle Partners] - providers of custom Moodle development services&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Developer tools]]&lt;br /&gt;
&lt;br /&gt;
[[ru:Development:Краткий обзор]]&lt;br /&gt;
[[es:Documentación para Desarrolladores]]&lt;br /&gt;
[[fr:Documentation développeur]]&lt;br /&gt;
[[pt:Desenvolvimento:Documentação para programadores]]&lt;br /&gt;
[[zh:开发者文档]]&lt;br /&gt;
[[ja:開発者ドキュメント]]&lt;br /&gt;
[[fi:Ohjelmoijan opas]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:Developer_documentation&amp;diff=82196</id>
		<title>Development:Developer documentation</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:Developer_documentation&amp;diff=82196"/>
		<updated>2011-03-23T13:34:18Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* Make a new plugin */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[image:moodle-development-logo.jpg|right|400px]]&lt;br /&gt;
&lt;br /&gt;
This [[:Category:Developer|Developer]] section of Moodle Docs is aimed at developers who contribute to the Moodle code, plugins, themes, and so on.&lt;br /&gt;
&lt;br /&gt;
* If you manage a Moodle site, [[Administrator documentation]] may suit your needs better. &lt;br /&gt;
* If you teach using Moodle, try [[Teacher documentation]].&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;p class=&amp;quot;note&amp;quot;&amp;gt;&#039;&#039;&#039;Note:&#039;&#039;&#039; New developer documentation pages should be added to the &#039;&#039;Development namespace&#039;&#039; by typing &amp;lt;code&amp;gt;Development:&amp;lt;/code&amp;gt; before the new page name i.e. &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[Development:New page name]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;. If you are a developer, you probably want to change your [[Special:Preferences|preferences]] to include the Development namespace in searches.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A page may be added to the Developer category by adding the template &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{CategoryDeveloper}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to the bottom of the page. - If required, you can use &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;[[Category:Developer|Sort key]]&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; to provide a sort key other than the default page name.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==How Moodle development works==&lt;br /&gt;
&lt;br /&gt;
The [[Development:Overview|overview of the Moodle development process]] explains how Moodle development occurs and how people become Moodle developers. Current plans are listed on the [[Roadmap]].&lt;br /&gt;
&lt;br /&gt;
You can also enrol in one of the [http://dev.moodle.org Moodle Developer Courses].&lt;br /&gt;
&lt;br /&gt;
==Guidelines==&lt;br /&gt;
&lt;br /&gt;
The following guidelines are crucial reading for anyone wanting to contribute to the Moodle code base:&lt;br /&gt;
*[[Development:Coding|Coding guidelines]] have to be followed by all Moodle developers&lt;br /&gt;
*[[Moodle architecture]] gives an overview of how the Moodle code works&lt;br /&gt;
*[[Development:Process]] explains how changes are incorporated into Moodle&lt;br /&gt;
*[[Tracker]] explains the Moodle Tracker for keeping track of bugs, issues, feature requests etc&lt;br /&gt;
*[[Development:Working with the Community|Working with the Community]] explains how to engage with the dev community and discuss changes&lt;br /&gt;
*[[Development:Unit tests|Unit tests]] explains how to run the unit tests, and how to write new test cases.&lt;br /&gt;
*[[Development:Profiling PHP|Profiling PHP]] how to analyse your code to find out why it is slow.&lt;br /&gt;
*[[Development:Fast portable SQL]] shows SQL techniques that are fast, efficient, and known to work on all supported DBs.&lt;br /&gt;
*[[Development:Development hints and tips]] a (developing) list of general wisdom to help with your Moodle projects.&lt;br /&gt;
&lt;br /&gt;
==Documentation for core components==&lt;br /&gt;
&lt;br /&gt;
This section is for documentation of specific components of the existing core Moodle code. Discussion of components that are under discussion or in development can be found in the [[Development:Developer notes|developer notes]] or on the [[Roadmap|roadmap]].&lt;br /&gt;
&lt;br /&gt;
The documents below give a general overview. For detailed function-by-function documentation, see the [http://phpdocs.moodle.org/ phpDocumentor] documentation that is automatically generated from the comments in the code. &lt;br /&gt;
&lt;br /&gt;
And don&#039;t forget that the most up-to-date and detailed description of how the code works is the code itself, and you can [http://xref.moodle.org/nav.html?index.html browse the code online] using [[Development:PHPXref|PHPXref]].&lt;br /&gt;
&lt;br /&gt;
===Core components ===&lt;br /&gt;
&lt;br /&gt;
*[[Development:XMLDB_Documentation|Database abstraction layer]] @ v[[1.7]]&lt;br /&gt;
*[[Development:Roles|Roles and Capabilities system]] @ v[[1.7]] for controlling who can do what&lt;br /&gt;
*[[Development:lib/formslib.php|Forms library]] @ v[[1.8]] for creating accessible and secure HTML forms that let users edit things&lt;br /&gt;
*[[Development:Using_the_file_API|File API]] @ v[[2.0]] for managing files stored by Moodle&lt;br /&gt;
*[[Development:Database schema introduction|The database schema]]&lt;br /&gt;
*[[Development:What happens when you require config.php|What happens when you require config.php]]&lt;br /&gt;
*[[Development:lib/moodlelib.php|lib/moodlelib.php]]&lt;br /&gt;
*[[Development:lib/weblib.php|lib/weblib.php]] for outputting stuff&lt;br /&gt;
&lt;br /&gt;
===Core libraries with a more specific uses===&lt;br /&gt;
&lt;br /&gt;
*[[Authentication API]]&lt;br /&gt;
*[[Cookieless Sessions]]&lt;br /&gt;
*[[Email processing]]&lt;br /&gt;
*[[Development:Environment checking|Environment checking]] before install, check the user&#039;s server to ensure Moodle will work there.&lt;br /&gt;
*[[Development:Groups|Groups system]]&lt;br /&gt;
*[[Development:Grades|Gradebook]]&lt;br /&gt;
*[[Development:Moodle Network|Moodle Network]]&lt;br /&gt;
*[[Question engine]]&lt;br /&gt;
*[[Stats package]]&lt;br /&gt;
*[[UTF-8 migration|Migration to UTF-8]] @ v[[:Category:Moodle 1.6|1.6]]&lt;br /&gt;
*[http://developer.yahoo.com/yui YUI JavaScript library] - YUI was selected as the official AJAX library for Moodle.&lt;br /&gt;
*[[Development:lib/graphlib|lib/graphlib]]&lt;br /&gt;
*[[Development:Admin settings|Admin settings]]&lt;br /&gt;
&lt;br /&gt;
===Modules included in the standard distribution===&lt;br /&gt;
&lt;br /&gt;
*[[Development:Lesson Specification|Lesson Specification]]&lt;br /&gt;
*[[Quiz developer docs|Quiz module]]&lt;br /&gt;
*[[SCORM schema|SCORM module 1.5 schema]]&lt;br /&gt;
&lt;br /&gt;
==How you can contribute==&lt;br /&gt;
&lt;br /&gt;
===Make a new plugin===&lt;br /&gt;
&lt;br /&gt;
The M in Moodle stands for modular, and the easiest, most maintainable way to add new functionality to Moodle is by using one of the many plugin APIs. There are many types of plugin you can write:&lt;br /&gt;
*[[Development:Modules|Activity modules]], see also [[Development:NEWMODULE Documentation]] (work in progress)&lt;br /&gt;
**and [[Development:Subplugins|Sub-Plugins]]&lt;br /&gt;
*[[Development:Admin reports|Admin reports]]&lt;br /&gt;
*[[Development:Assignment types|Assignment types]]&lt;br /&gt;
*[[Development:Authentication plugins|Authentication plugins]]&lt;br /&gt;
*[[Development:Blocks|Blocks]]&lt;br /&gt;
*Content editors (2.0 onwards)&lt;br /&gt;
*[[Course formats]]&lt;br /&gt;
*[[Development:Course Report Plugins|Course reports]]&lt;br /&gt;
*Course importers (2.0 onwards)&lt;br /&gt;
*[[Development:Database fields|Database fields]]&lt;br /&gt;
*[[Development:Database presets|Database presets]]&lt;br /&gt;
*[[Development:Enrolment plugins|Enrolment plugins]]&lt;br /&gt;
*[[Development:Filters|Filters]]&lt;br /&gt;
*[[Development:Gradebook_Report_Tutorial|Gradebook report]]&lt;br /&gt;
*[[Development:Gradebook export|Gradebook export]]&lt;br /&gt;
*[[Development:Gradebook import|Gradebook import]]&lt;br /&gt;
*Message senders (2.0 onwards)&lt;br /&gt;
*Mnet services&lt;br /&gt;
*Plagiarism detection plugins (2.0 onwards)&lt;br /&gt;
*[[Development:Writing_a_Portfolio_Plugin|Portfolio plugins]] (2.0 onwards)&lt;br /&gt;
*[[Development:Question_type_plugin_how_to|Question types]]&lt;br /&gt;
*[[Development:Question import/export formats|Question import/export formats]]&lt;br /&gt;
*[[Development:How to write a quiz report plugin|Quiz reports]]&lt;br /&gt;
*[[Development:Repository plugins|Repository plugins]] (2.0 onwards)&lt;br /&gt;
*[[Development:Resource types|Resource types]]&lt;br /&gt;
*[[Development:Search engine adapters|Search engine adapters]]&lt;br /&gt;
*Themes which are different in [[Development:Themes_2.0|Moodle 2.0]], and [[Theme_basics|earlier versions]].&lt;br /&gt;
*User profile fields&lt;br /&gt;
*[[Development:Web services (2.0 onwards)|Web services (2.0 onwards)]]&lt;br /&gt;
*Workshop allocators (2.0 onwards)&lt;br /&gt;
*Workshop forms (2.0 onwards)&lt;br /&gt;
*Workshop evaluators (2.0 onwards)&lt;br /&gt;
&lt;br /&gt;
General information that applies to all types of plugins&lt;br /&gt;
*[[Development:Places to search for lang strings|Where to put language strings for your plugin]]&lt;br /&gt;
*[[Development:Installing and upgrading plugin database tables|Defining the database tables for your plugin]]&lt;br /&gt;
&lt;br /&gt;
Please see the [[Development:Guidelines for contributed code|Guidelines for contributed code]] for an overview of how to contribute to the Moodle code.&lt;br /&gt;
&lt;br /&gt;
Sometimes it is not possible to write a proper plugin for what you want to do, in which case you may have to resort to using the [[Development:Local_customisation|local customisations]] hook.&lt;br /&gt;
&lt;br /&gt;
===Change core code===&lt;br /&gt;
&lt;br /&gt;
Some types of change can only be made by editing the core Moodle code. Such changes are much harder to maintain than plugins. If you want your core change to be considered for inclusion in the official Moodle release, you need to create an issue in the [[Tracker|tracker]], and attach your change as a [[Development:How_to_create_a_patch|patch]]. It is also a good idea to discuss your ideas in the forums first.  See [[Development:Overview#Major_Development]] for more details.&lt;br /&gt;
&lt;br /&gt;
===Ways to contribute that do not involve PHP programming===&lt;br /&gt;
&lt;br /&gt;
*[[Themes|Create Moodle themes]]&lt;br /&gt;
*[[Translation|Translate Moodle into other languages]]&lt;br /&gt;
*[[MoodleDocs:Guidelines for contributors|Help document Moodle]]&lt;br /&gt;
*[[Development:Tests|Join the testing effort]], which involves [[Tracker|participating in the bug tracker]]&lt;br /&gt;
&lt;br /&gt;
==Plans for the future==&lt;br /&gt;
&lt;br /&gt;
Ideas for and details of planned future features of Moodle are initially discussed on the forums in the [http://moodle.org/course/view.php?id=5 Using Moodle] course at moodle.org. That developer discussions are intermixed with user discussions in the same forums may seem strange at first but is one of the reasons for the success of Moodle. It is important that both end-users and developers discuss the future features together.&lt;br /&gt;
&lt;br /&gt;
Once ideas begin to crystallize on the forums they can be summarized in this wiki, either as part of the [[Roadmap|roadmap]] or in the form of [[Development:Developer notes|developer notes]]. These pages then form the basis for further discussion in the forums.&lt;br /&gt;
&lt;br /&gt;
*[[Roadmap]]&lt;br /&gt;
*[[Development:Developer notes|Developer notes]]&lt;br /&gt;
*[[Student projects]]&lt;br /&gt;
*[[Developer meetings]]&lt;br /&gt;
&lt;br /&gt;
== Resources ==&lt;br /&gt;
&lt;br /&gt;
*[[Developer FAQ]] - frequently asked questions, especially useful for newcomers to Moodle&lt;br /&gt;
*[[Development:Finding_your_way_into_the_Moodle_code|Finding your way into the Moodle code]] - also aimed at newcomers&lt;br /&gt;
*[http://tracker.moodle.org/ Moodle tracker] - bug reports, feature requests and other tracked issues&lt;br /&gt;
**[[Firefox tracker search]] - How to setup a firefox quicksearch to easily navigate to moodle bugs&lt;br /&gt;
**[[Firefox tracker search#Firefox Search Plugins|Firefox Search Plugins]] - Find tracked issues even more easily&lt;br /&gt;
*[[Unmerged files]] - changes on the stable branch in CVS that have not been merged to [[HEAD]]&lt;br /&gt;
*Browse the code online:&lt;br /&gt;
**[http://cvs.moodle.org/moodle/ the code with a complete change history from CVS]&lt;br /&gt;
**[http://xref.moodle.org/index.html the code, with links generated by PHPXref]&lt;br /&gt;
*[http://phpdocs.moodle.org/ Moodle PHP doc reference] - compiled nightly from the comment attached to each class and function in the code.  &lt;br /&gt;
*[[Development:Database Schema|Database Schema]] - for recent releases&lt;br /&gt;
*[http://moodle.org/course/view.php?id=5#4 Development news and discussion] section of Using Moodle course&lt;br /&gt;
**especially the [http://moodle.org/mod/forum/view.php?id=55 General developer forum]&lt;br /&gt;
**[[Filters used on the Moodle.org forums|cool tricks you can use in the moodle.org forums]]&lt;br /&gt;
&lt;br /&gt;
== Tools ==&lt;br /&gt;
Some tools people use when working on Moodle code:&lt;br /&gt;
&lt;br /&gt;
=== IDEs ===&lt;br /&gt;
&lt;br /&gt;
* [[Development:Setting_up_Netbeans|Setting up NetBeans for Moodle development]] - NetBeans for PHP is a great out-of-the-box editor.&lt;br /&gt;
* [[Development:Setting_up_Eclipse|Setting up Eclipse for Moodle development]] - Eclipse is a great editor to use for php development, if you can work out how to set it up.&lt;br /&gt;
* [[Development:vim|Setting up Vim for Moodle development]]&lt;br /&gt;
* [http://www.aptana.com/ Aptana Studio 2]&lt;br /&gt;
&lt;br /&gt;
=== Browser add-ons ===&lt;br /&gt;
*[http://getfirebug.com Firebug], see [[Firebug]] for details.&lt;br /&gt;
* [[Web developer extension]]&lt;br /&gt;
* [https://addons.mozilla.org/en-US/firefox/addon/394 ViewSourceWith] - The main goal is to view page source with external applications, but you can do a lot of other things as well.&lt;br /&gt;
&lt;br /&gt;
=== Miscellaneous === &lt;br /&gt;
*[[Development:ctags|Ctags]] - Using a tags file to navigate code&lt;br /&gt;
*[[W3C_validation|W3C HTML validator]] - Moodle has built in support to make using it easier.&lt;br /&gt;
*[[Development:Windows Installer|Windows Installer]] - Windows Installer documentation for developer.&lt;br /&gt;
&lt;br /&gt;
See also: [http://dev.moodle.org/mod/forum/view.php?id=18 Useful Development Tools forum]in the [http://dev.moodle.org/course/view.php?id=2 Introduction to Moodle Programming course]&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/security/ Moodle Security Announcements]&lt;br /&gt;
*[http://moodle.com/partners/ Moodle Partners] - providers of custom Moodle development services&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:Developer tools]]&lt;br /&gt;
&lt;br /&gt;
[[ru:Development:Краткий обзор]]&lt;br /&gt;
[[es:Documentación para Desarrolladores]]&lt;br /&gt;
[[fr:Documentation développeur]]&lt;br /&gt;
[[pt:Desenvolvimento:Documentação para programadores]]&lt;br /&gt;
[[zh:开发者文档]]&lt;br /&gt;
[[ja:開発者ドキュメント]]&lt;br /&gt;
[[fi:Ohjelmoijan opas]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81945</id>
		<title>Maintaining Moodle customisations with Git</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81945"/>
		<updated>2011-03-15T11:31:57Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This page is a work in progress&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Git makes it very easy to maintain local customisations to Moodle alongside updates from the official Moodle repository.&lt;br /&gt;
This page assumes you installed Moodle following [[Installing Moodle from Git repository]]. It also assumes you understand basic version control principles (repositories, branches, conflicts) and have a basic working knowledge of Git.&lt;br /&gt;
&lt;br /&gt;
First, from your moodle directory, create a branch of &amp;lt;tt&amp;gt;master&amp;lt;/tt&amp;gt; which will contain your customised Moodle. This is the branch you&#039;ll publish to other servers.&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git checkout -b mycustommoodle&lt;br /&gt;
&lt;br /&gt;
 Switched to a new branch &#039;mycustommoodle&#039;&lt;br /&gt;
Next, create a new branch for developing your customisation, and move to that branch:&lt;br /&gt;
 git checkout -b myfeature&lt;br /&gt;
&lt;br /&gt;
 Switched to a new branch &#039;myfeature&#039;&lt;br /&gt;
This will give you a seperate copy of the Moodle code to work on without affecting the master branch. It&#039;s not recommended that you do this on your production server, as it will cause the code to be available immediately as it&#039;s saved.&lt;br /&gt;
&lt;br /&gt;
Do your customisations, add any new files to git, and commit the changes&lt;br /&gt;
 git add .&lt;br /&gt;
 git status&lt;br /&gt;
 git commit -m &amp;quot;Description of the change&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Switch back to the &amp;lt;tt&amp;gt;mycustommoodle&amp;lt;/tt&amp;gt; branch and merge the changes&lt;br /&gt;
 git checkout mycustommoodle&lt;br /&gt;
 git merge myfeature&lt;br /&gt;
Any future development can take place on the myfeature branch, and be merged into mycustommoodle in this way&lt;br /&gt;
&lt;br /&gt;
Even after local modifications have been made, you can pull in updates from the official git repository&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git fetch&lt;br /&gt;
 git merge origin/master&lt;br /&gt;
 git checkout mycustommoodle&lt;br /&gt;
 git merge master&lt;br /&gt;
&lt;br /&gt;
=== Conflicts ===&lt;br /&gt;
If you create a local modification to a file, and that same file is modified in the official repository, you may find that a conflict is created when you do &amp;lt;tt&amp;gt;git merge origin/master&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To resolve this, you will need to find the conflicts (the attempt to merge will tell you where they are) and resolve them.  The [http://www.kernel.org/pub/software/scm/git/docs/git-merge.html|&amp;lt;tt&amp;gt;git merge&amp;lt;/tt&amp;gt; man page] has more information on the presentation and resolution of conflicts.&lt;br /&gt;
&lt;br /&gt;
After the conflict is resolved, you&#039;ll need to commit the resolved files.&lt;br /&gt;
 git commit -a&lt;br /&gt;
Once a conflict has been resolved, even if you keep your local modification over the upstream modification, there wont be a conflict next time you merge.&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Git_repositories_for_contrib_modules&amp;diff=81937</id>
		<title>Git repositories for contrib modules</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Git_repositories_for_contrib_modules&amp;diff=81937"/>
		<updated>2011-03-15T09:37:45Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* Installing a third-party plugin */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This page is a work in progress.&#039;&#039;&#039; The instructions here assume that you have a working knowledge of git.&lt;br /&gt;
&lt;br /&gt;
Managing contrib plugin with git makes it easy to make local modifications and pull in updates.&lt;br /&gt;
There are several options for managing a contrib plugin with git:&lt;br /&gt;
# Add the module to your main moodle git repository&lt;br /&gt;
# Create a self-contained repository for the plugin in a subdirectory&lt;br /&gt;
# Create a git submodule, which creates a repository for the plugin but tracks updates in the main repository too. It also allows you to clone the plugins with the main repository&lt;br /&gt;
Having used all of the above, the method I&#039;d recommend is number 2, as it&#039;s most convenient. The main disadvantage of 1 is that you can&#039;t easily pull in updates, and the main disadvantage of 3 is that you have to make each commit to the module twice (once in the submodule, and once in the main repo).&lt;br /&gt;
&lt;br /&gt;
== Creating a new plugin ==&lt;br /&gt;
If you intend to publish the plugin, I highly recommend creating a [http://github.org github] repository from the start. This will allow you to publish with a single command when you&#039;re ready.  Just go to the site, sign up for an account, create a new repository. The naming convention for Moodle plugin repositories is &amp;lt;tt&amp;gt;moodle-plugintype_pluginname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Github will give you instructions for cloning your (blank) repository. If you&#039;re using option 2 above, navigate to the directory for the plugin type you&#039;re developing (e.g. /block, /mod, /local) and run the &amp;lt;tt&amp;gt;git clone&amp;lt;/tt&amp;gt; command there. This will create a subdirectory called &amp;lt;tt&amp;gt;moodle-plugintype_pluginname&amp;lt;/tt&amp;gt;, rename this to &amp;lt;tt&amp;gt;pluginname&amp;lt;/tt&amp;gt; and you&#039;re good to go. &amp;lt;tt&amp;gt;cd&amp;lt;/tt&amp;gt; into this directory to perform git commands on this plugin&#039;s repository - outside of this directory will perform them on the main Moodle repository.&lt;br /&gt;
&lt;br /&gt;
You can then develop and test your changes locally, and when you&#039;re ready to publish, run&lt;br /&gt;
 git push origin&lt;br /&gt;
&lt;br /&gt;
== Installing a third-party plugin ==&lt;br /&gt;
Installing a plugin developed by a third party differs depending on whether they have used git or not.&lt;br /&gt;
If they have used git, you can follow the instructions above, but skip out the part where you create a new github repository and clone their own github (or other public repository) instead.&lt;br /&gt;
&lt;br /&gt;
If they haven&#039;t used git, you can still use git (and even github, if you like) to track local modifications to the plugin. Simply create a directory for the plugin&lt;br /&gt;
 mkdir ~/moodle/blocks/newblock&lt;br /&gt;
Initialise a new git repository there&lt;br /&gt;
 cd ~/moodle/blocks/newblock&lt;br /&gt;
 git init&lt;br /&gt;
unzip or copy the files to the repository&lt;br /&gt;
 cd ~&lt;br /&gt;
 tar -xf newblock.tar.gz&lt;br /&gt;
 cp newblock/* ~/moodle/blocks/newblock&lt;br /&gt;
add and commit the files&lt;br /&gt;
 cd ~/moodle/blocks/newblock&lt;br /&gt;
 git add .&lt;br /&gt;
 git commit . -m &amp;quot;Added files for newblock&amp;quot;&lt;br /&gt;
When installing updates, you&#039;ll need to copy the new files in place of the old one, and re run the &amp;lt;tt&amp;gt;git add&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;git commit&amp;lt;/tt&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
== Moving a plugin to it&#039;s own repository ==&lt;br /&gt;
You may have developed a plugin within your main Moodle repository, but want to move it to a separate one to make it easier to publish.  Using &amp;lt;tt&amp;gt;git filter-branch&amp;lt;/tt&amp;gt;, we can achieve this and maintain all existing history for the plugin&#039;s files.&lt;br /&gt;
&lt;br /&gt;
First, you&#039;ll need a fresh copy of moodle (this will become your new moodle repository)&lt;br /&gt;
 mkdir ~/newmoodle&lt;br /&gt;
 cd ~/newmoodle&lt;br /&gt;
 git clone git://git.moodle.org/moodle.git&lt;br /&gt;
This will create a clone of Moodle without your plugins in ~/newmoodle/moodle&lt;br /&gt;
Next, you need to clone your local Moodle repository (why will become clear).&lt;br /&gt;
 mkdir ~/moodleclone&lt;br /&gt;
 cd ~/moodleclone&lt;br /&gt;
 git clone ~/moodle&lt;br /&gt;
This will create a clone of your current moodle development repository, with your plugins, in ~/moodleclone/moodle&lt;br /&gt;
Now, we&#039;ll use the &amp;lt;tt&amp;gt;git filter-branch&amp;lt;/tt&amp;gt; command to reduce this clone to just the plugin. &lt;br /&gt;
 cd ~/moodleclone/moodle&lt;br /&gt;
 git filter-branch --subdirectory-filter blocks/myblock/&lt;br /&gt;
The files from blocks/myblock/ will now be at the root of the repository. All other files will have been removed (this is why we&#039;re using a clone).&lt;br /&gt;
You can now track the plugin in it&#039;s own repository by cloning this reduced repository to a subdirectory of the new moodle clone.&lt;br /&gt;
 cd ~/newmoodle/blocks&lt;br /&gt;
 git clone ~/moodleclone/moodle myblock&lt;br /&gt;
This will clone the block&#039;s files, with the full history, into their own repository in the myblock subdirectory.&lt;br /&gt;
You can now delete ~/moodleclone/moodle, and repeat with any other plugins you&#039;ve developed.&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Git_repositories_for_contrib_modules&amp;diff=81936</id>
		<title>Git repositories for contrib modules</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Git_repositories_for_contrib_modules&amp;diff=81936"/>
		<updated>2011-03-15T09:36:21Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This page is a work in progress.&#039;&#039;&#039; The instructions here assume that you have a working knowledge of git.&lt;br /&gt;
&lt;br /&gt;
Managing contrib plugin with git makes it easy to make local modifications and pull in updates.&lt;br /&gt;
There are several options for managing a contrib plugin with git:&lt;br /&gt;
# Add the module to your main moodle git repository&lt;br /&gt;
# Create a self-contained repository for the plugin in a subdirectory&lt;br /&gt;
# Create a git submodule, which creates a repository for the plugin but tracks updates in the main repository too. It also allows you to clone the plugins with the main repository&lt;br /&gt;
Having used all of the above, the method I&#039;d recommend is number 2, as it&#039;s most convenient. The main disadvantage of 1 is that you can&#039;t easily pull in updates, and the main disadvantage of 3 is that you have to make each commit to the module twice (once in the submodule, and once in the main repo).&lt;br /&gt;
&lt;br /&gt;
== Creating a new plugin ==&lt;br /&gt;
If you intend to publish the plugin, I highly recommend creating a [http://github.org github] repository from the start. This will allow you to publish with a single command when you&#039;re ready.  Just go to the site, sign up for an account, create a new repository. The naming convention for Moodle plugin repositories is &amp;lt;tt&amp;gt;moodle-plugintype_pluginname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Github will give you instructions for cloning your (blank) repository. If you&#039;re using option 2 above, navigate to the directory for the plugin type you&#039;re developing (e.g. /block, /mod, /local) and run the &amp;lt;tt&amp;gt;git clone&amp;lt;/tt&amp;gt; command there. This will create a subdirectory called &amp;lt;tt&amp;gt;moodle-plugintype_pluginname&amp;lt;/tt&amp;gt;, rename this to &amp;lt;tt&amp;gt;pluginname&amp;lt;/tt&amp;gt; and you&#039;re good to go. &amp;lt;tt&amp;gt;cd&amp;lt;/tt&amp;gt; into this directory to perform git commands on this plugin&#039;s repository - outside of this directory will perform them on the main Moodle repository.&lt;br /&gt;
&lt;br /&gt;
You can then develop and test your changes locally, and when you&#039;re ready to publish, run&lt;br /&gt;
 git push origin&lt;br /&gt;
&lt;br /&gt;
== Installing a third-party plugin ==&lt;br /&gt;
Installing a plugin developed by a third party differs depending on whether they have used git or not.&lt;br /&gt;
If they have used git, you can follow the instructions above, but skip out the part where you create a new repository and clone their own git repository instead.&lt;br /&gt;
&lt;br /&gt;
If they haven&#039;t used git, you can still use git (and even github, if you like) to track local modifications to the plugin. Simply create a directory for the plugin&lt;br /&gt;
 mkdir ~/moodle/blocks/newblock&lt;br /&gt;
Initialise a new git repository there&lt;br /&gt;
 cd ~/moodle/blocks/newblock&lt;br /&gt;
 git init&lt;br /&gt;
unzip or copy the files to the repository&lt;br /&gt;
 cd ~&lt;br /&gt;
 tar -xf newblock.tar.gz&lt;br /&gt;
 cp newblock/* ~/moodle/blocks/newblock&lt;br /&gt;
add and commit the files&lt;br /&gt;
 cd ~/moodle/blocks/newblock&lt;br /&gt;
 git add .&lt;br /&gt;
 git commit . -m &amp;quot;Added files for newblock&amp;quot;&lt;br /&gt;
When installing updates, you&#039;ll need to copy the new files in place of the old one, and re run the &amp;lt;tt&amp;gt;git add&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;git commit&amp;lt;/tt&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
== Moving a plugin to it&#039;s own repository ==&lt;br /&gt;
You may have developed a plugin within your main Moodle repository, but want to move it to a separate one to make it easier to publish.  Using &amp;lt;tt&amp;gt;git filter-branch&amp;lt;/tt&amp;gt;, we can achieve this and maintain all existing history for the plugin&#039;s files.&lt;br /&gt;
&lt;br /&gt;
First, you&#039;ll need a fresh copy of moodle (this will become your new moodle repository)&lt;br /&gt;
 mkdir ~/newmoodle&lt;br /&gt;
 cd ~/newmoodle&lt;br /&gt;
 git clone git://git.moodle.org/moodle.git&lt;br /&gt;
This will create a clone of Moodle without your plugins in ~/newmoodle/moodle&lt;br /&gt;
Next, you need to clone your local Moodle repository (why will become clear).&lt;br /&gt;
 mkdir ~/moodleclone&lt;br /&gt;
 cd ~/moodleclone&lt;br /&gt;
 git clone ~/moodle&lt;br /&gt;
This will create a clone of your current moodle development repository, with your plugins, in ~/moodleclone/moodle&lt;br /&gt;
Now, we&#039;ll use the &amp;lt;tt&amp;gt;git filter-branch&amp;lt;/tt&amp;gt; command to reduce this clone to just the plugin. &lt;br /&gt;
 cd ~/moodleclone/moodle&lt;br /&gt;
 git filter-branch --subdirectory-filter blocks/myblock/&lt;br /&gt;
The files from blocks/myblock/ will now be at the root of the repository. All other files will have been removed (this is why we&#039;re using a clone).&lt;br /&gt;
You can now track the plugin in it&#039;s own repository by cloning this reduced repository to a subdirectory of the new moodle clone.&lt;br /&gt;
 cd ~/newmoodle/blocks&lt;br /&gt;
 git clone ~/moodleclone/moodle myblock&lt;br /&gt;
This will clone the block&#039;s files, with the full history, into their own repository in the myblock subdirectory.&lt;br /&gt;
You can now delete ~/moodleclone/moodle, and repeat with any other plugins you&#039;ve developed.&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81935</id>
		<title>Maintaining Moodle customisations with Git</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81935"/>
		<updated>2011-03-15T09:33:38Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This page is a work in progress&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Git makes it very easy to maintain local customisations to Moodle alongside updates from the official Moodle repository.&lt;br /&gt;
This page assumes you installed Moodle following [[Installing Moodle from Git repository]]. It also assumes you understand basic version control principles (repositories, branches, conflicts) and have a basic working knowledge of Git.&lt;br /&gt;
&lt;br /&gt;
From your moodle directory, create a new branch for developing your customisation, and move to that branch:&lt;br /&gt;
 git checkout -b myfeature&lt;br /&gt;
&lt;br /&gt;
 Switched to a new branch &#039;myfeature&#039;&lt;br /&gt;
This will give you a seperate copy of the Moodle code to work on without affecting the master branch. It&#039;s not recommended that you do this on your production server, as it will cause the code to be available immediately as it&#039;s saved.&lt;br /&gt;
&lt;br /&gt;
Do your customisations, add any new files to git, and commit the changes&lt;br /&gt;
 git add .&lt;br /&gt;
 git status&lt;br /&gt;
 git commit -m &amp;quot;Description of the change&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Ouch! this next bit is a really bad idea. I don&#039;t know what you are trying to achieve, but this is not the right way to do it!!!--[[User:Tim Hunt|Tim Hunt]] 09:09, 15 March 2011 (UTC)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Please edit it to the right way to do it then, it hasn&#039;t caused me any problems (yet) :-)[[User:Mark Johnson|Mark Johnson]]&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switch back to the master branch and merge the changes&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git merge myfeature&lt;br /&gt;
Any future development can take place on the myfeature branch, and be merged into master in this way&lt;br /&gt;
&lt;br /&gt;
Even after local modifications have been made, you can pull in updates from the official git repository&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git fetch&lt;br /&gt;
 git merge origin/master&lt;br /&gt;
&lt;br /&gt;
=== Conflicts ===&lt;br /&gt;
If you create a local modification to a file, and that same file is modified in the official repository, you may find that a conflict is created when you do &amp;lt;tt&amp;gt;git merge origin/master&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To resolve this, you will need to find the conflicts (the attempt to merge will tell you where they are) and resolve them.  The [http://www.kernel.org/pub/software/scm/git/docs/git-merge.html|&amp;lt;tt&amp;gt;git merge&amp;lt;/tt&amp;gt; man page] has more information on the presentation and resolution of conflicts.&lt;br /&gt;
&lt;br /&gt;
After the conflict is resolved, you&#039;ll need to commit the resolved files.&lt;br /&gt;
 git commit -a&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81934</id>
		<title>Maintaining Moodle customisations with Git</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81934"/>
		<updated>2011-03-15T09:32:35Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This page is a work in progress&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Git makes it very easy to maintain local customisations to Moodle alongside updates from the official Moodle repository.&lt;br /&gt;
This page assumes you installed Moodle following [[Installing Moodle from Git repository]]. It also assumes you understand basic version control principles (repositories, branches, conflicts) and have a basic working knowledge of Git.&lt;br /&gt;
&lt;br /&gt;
From your moodle directory, create a new branch for developing your customisation, and move to that branch:&lt;br /&gt;
 git checkout -b myfeature&lt;br /&gt;
&lt;br /&gt;
 Switched to a new branch &#039;myfeature&#039;&lt;br /&gt;
This will give you a seperate copy of the Moodle code to work on without affecting the master branch. It&#039;s not recommended that you do this on your production server, as it will cause the code to be available immediately as it&#039;s saved.&lt;br /&gt;
&lt;br /&gt;
Do your customisations, add any new files to git, and commit the changes&lt;br /&gt;
 git add .&lt;br /&gt;
 git status&lt;br /&gt;
 git commit -m &amp;quot;Description of the change&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Ouch! this next bit is a really bad idea. I don&#039;t know what you are trying to achieve, but this is not the right way to do it!!!--[[User:Tim Hunt|Tim Hunt]] 09:09, 15 March 2011 (UTC)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Please edit it to the right way to do it then :-)[[User:Mark Johnson|Mark Johnson]]&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switch back to the master branch and merge the changes&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git merge myfeature&lt;br /&gt;
Any future development can take place on the myfeature branch, and be merged into master in this way&lt;br /&gt;
&lt;br /&gt;
Even after local modifications have been made, you can pull in updates from the official git repository&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git fetch&lt;br /&gt;
 git merge origin/master&lt;br /&gt;
&lt;br /&gt;
=== Conflicts ===&lt;br /&gt;
If you create a local modification to a file, and that same file is modified in the official repository, you may find that a conflict is created when you do &amp;lt;tt&amp;gt;git merge origin/master&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To resolve this, you will need to find the conflicts (the attempt to merge will tell you where they are) and resolve them.  The [http://www.kernel.org/pub/software/scm/git/docs/git-merge.html|&amp;lt;tt&amp;gt;git merge&amp;lt;/tt&amp;gt; man page] has more information on the presentation and resolution of conflicts.&lt;br /&gt;
&lt;br /&gt;
After the conflict is resolved, you&#039;ll need to commit the resolved files.&lt;br /&gt;
 git commit -a&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81933</id>
		<title>Maintaining Moodle customisations with Git</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81933"/>
		<updated>2011-03-15T09:30:52Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This page is a work in progress&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Git makes it very easy to maintain local customisations to Moodle alongside updates from the official Moodle repository.&lt;br /&gt;
This page assumes you installed Moodle following [[Installing Moodle from Git repository]]. It also assumes you understand basic version control principles (repositories, branches, conflicts) and have a basic working knowledge of Git.&lt;br /&gt;
&lt;br /&gt;
From your moodle directory, create a new branch for developing your customisation, and move to that branch:&lt;br /&gt;
 git checkout -b myfeature&lt;br /&gt;
&lt;br /&gt;
 Switched to a new branch &#039;myfeature&#039;&lt;br /&gt;
This will give you a seperate copy of the Moodle code to work on without affecting the master branch. It&#039;s not recommended that you do this on your production server, as it will cause the code to be available immediately as it&#039;s saved.&lt;br /&gt;
&lt;br /&gt;
Do your customisations, add any new files to git, and commit the changes&lt;br /&gt;
 git add .&lt;br /&gt;
 git status&lt;br /&gt;
 git commit -m &amp;quot;Description of the change&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;Ouch! this next bit is a really bad idea. I don&#039;t know what you are trying to achieve, but this is not the right way to do it!!!--[[User:Tim Hunt|Tim Hunt]] 09:09, 15 March 2011 (UTC)&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Switch back to the master branch and merge the changes&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git merge myfeature&lt;br /&gt;
Any future development can take place on the myfeature branch, and be merged into master in this way&lt;br /&gt;
&lt;br /&gt;
Even after local modifications have been made, you can pull in updates from the official git repository&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git fetch&lt;br /&gt;
 git merge origin/master&lt;br /&gt;
&lt;br /&gt;
=== Conflicts ===&lt;br /&gt;
If you create a local modification to a file, and that same file is modified in the official repository, you may find that a conflict is created when you do &amp;lt;tt&amp;gt;git merge origin/master&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To resolve this, you will need to find the conflicts (the attempt to merge will tell you where they are) and resolve them.  The [http://www.kernel.org/pub/software/scm/git/docs/git-merge.html|&amp;lt;tt&amp;gt;git merge&amp;lt;/tt&amp;gt; man page] has more information on the presentation and resolution of conflicts.&lt;br /&gt;
&lt;br /&gt;
After the conflict is resolved, you&#039;ll need to commit the resolved files.&lt;br /&gt;
 git commit -a&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Installing_Moodle_from_Git_repository&amp;diff=81932</id>
		<title>Installing Moodle from Git repository</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Installing_Moodle_from_Git_repository&amp;diff=81932"/>
		<updated>2011-03-15T09:30:30Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Added caveats to the top of the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This page is a work in progress&#039;&#039;&#039;&lt;br /&gt;
== Linux/Unix command line ==&lt;br /&gt;
These instructions should be very similar on Windows.&lt;br /&gt;
&lt;br /&gt;
Move to the directory where you wish to install Moodle. Moodle will go in ./moodle, relative to this directory&lt;br /&gt;
 cd ~&lt;br /&gt;
Clone the offical Moodle repository via git&lt;br /&gt;
 git clone git://git.moodle.org/moodle.git&lt;br /&gt;
If you have firewall issues with the git protocol, the above may not work, in which case you can try cloning the official github repository via http&lt;br /&gt;
 git clone https://github.com/moodle/moodle.git&lt;br /&gt;
&lt;br /&gt;
 Initialized empty Git repository in ~/moodle/.git/&lt;br /&gt;
 remote: Counting objects: 448351, done.&lt;br /&gt;
 remote: Compressing objects: 100% (103262/103262), done.&lt;br /&gt;
 remote: Total 448351 (delta 336929), reused 446784 (delta 335924)&lt;br /&gt;
 Receiving objects: 100% (448351/448351), 128.54 MiB | 10.94 MiB/s, done.&lt;br /&gt;
 Resolving deltas: 100% (336929/336929), done.&lt;br /&gt;
Move in to the new moodle directory (you can rename this if you wish)&lt;br /&gt;
 cd moodle&lt;br /&gt;
From here, you can edit config.php and install as per the [[Installing_Moodle#Setting-up_your_web_server|Installation Instructions]]&lt;br /&gt;
Upgrading to the latest Moodle version is now 2 simple commands:&lt;br /&gt;
 git fetch&lt;br /&gt;
 git merge origin/master&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Git_repositories_for_contrib_modules&amp;diff=81931</id>
		<title>Git repositories for contrib modules</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Git_repositories_for_contrib_modules&amp;diff=81931"/>
		<updated>2011-03-15T09:29:57Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Added caveats to the top of the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;This page is a work in progress.&#039;&#039;&#039; The instructions here assume that you have a working knowledge of git.&lt;br /&gt;
&lt;br /&gt;
Managing contrib plugin with git makes it easy to make local modifications and pull in updates.&lt;br /&gt;
There are several options for managing a contrib plugin with git:&lt;br /&gt;
# Add the module to your main moodle git repository&lt;br /&gt;
# Create a self-contained repository for the plugin in a subdirectory&lt;br /&gt;
# Create a git submodule, which creates a repository for the plugin but tracks updates in the main repository too. It also allows you to clone the plugins with the main repository&lt;br /&gt;
Having used all of the above, the method I&#039;d recommend is number 2, as it&#039;s most convenient. The main disadvantage of 1 is that you can&#039;t easily pull in updates, and the main disadvantage of 3 is that you have to make each commit to the module twice.&lt;br /&gt;
&lt;br /&gt;
== Creating a new plugin ==&lt;br /&gt;
If you intend to publish the plugin, I highly recommend creating a [http://github.org github] repository from the start. This will allow you to publish with a single command when you&#039;re ready.  Just go to the site, sign up for an account, create a new repository. The naming convention for Moodle plugin repositories is &amp;lt;tt&amp;gt;moodle-plugintype_pluginname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Github will give you instructions for cloning your (blank) repository. If you&#039;re using option 2 above, navigate to the directory for the plugin type you&#039;re developing (e.g. /block, /mod, /local) and run the &amp;lt;tt&amp;gt;git clone&amp;lt;/tt&amp;gt; command there. This will create a subdirectory called &amp;lt;tt&amp;gt;moodle-plugintype_pluginname&amp;lt;/tt&amp;gt;, rename this to &amp;lt;tt&amp;gt;pluginname&amp;lt;/tt&amp;gt; and you&#039;re good to go. &amp;lt;tt&amp;gt;cd&amp;lt;/tt&amp;gt; into this directory to perform git commands on this plugin&#039;s repository - outside of this directory will perform them on the main Moodle repository.&lt;br /&gt;
&lt;br /&gt;
You can then develop and test your changes locally, and when you&#039;re ready to publish, run&lt;br /&gt;
 git push origin&lt;br /&gt;
&lt;br /&gt;
== Installing a third-party plugin ==&lt;br /&gt;
Installing a plugin developed by a third party differs depending on whether they have used git or not.&lt;br /&gt;
If they have used git, you can follow the instructions above, but skip out the part where you create a new repository and clone their own git repository instead.&lt;br /&gt;
&lt;br /&gt;
If they haven&#039;t used git, you can still use git (and even github, if you like) to track local modifications to the plugin. Simply create a directory for the plugin&lt;br /&gt;
 mkdir ~/moodle/blocks/newblock&lt;br /&gt;
Initialise a new git repository there&lt;br /&gt;
 cd ~/moodle/blocks/newblock&lt;br /&gt;
 git init&lt;br /&gt;
unzip or copy the files to the repository&lt;br /&gt;
 cd ~&lt;br /&gt;
 tar -xf newblock.tar.gz&lt;br /&gt;
 cp newblock/* ~/moodle/blocks/newblock&lt;br /&gt;
add and commit the files&lt;br /&gt;
 cd ~/moodle/blocks/newblock&lt;br /&gt;
 git add .&lt;br /&gt;
 git commit . -m &amp;quot;Added files for newblock&amp;quot;&lt;br /&gt;
When installing updates, you&#039;ll need to copy the new files in place of the old one, and re run the &amp;lt;tt&amp;gt;git add&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;git commit&amp;lt;/tt&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
== Moving a plugin to it&#039;s own repository ==&lt;br /&gt;
You may have developed a plugin within your main Moodle repository, but want to move it to a separate one to make it easier to publish.  Using &amp;lt;tt&amp;gt;git filter-branch&amp;lt;/tt&amp;gt;, we can achieve this and maintain all existing history for the plugin&#039;s files.&lt;br /&gt;
&lt;br /&gt;
First, you&#039;ll need a fresh copy of moodle (this will become your new moodle repository)&lt;br /&gt;
 mkdir ~/newmoodle&lt;br /&gt;
 cd ~/newmoodle&lt;br /&gt;
 git clone git://git.moodle.org/moodle.git&lt;br /&gt;
This will create a clone of Moodle without your plugins in ~/newmoodle/moodle&lt;br /&gt;
Next, you need to clone your local Moodle repository (why will become clear).&lt;br /&gt;
 mkdir ~/moodleclone&lt;br /&gt;
 cd ~/moodleclone&lt;br /&gt;
 git clone ~/moodle&lt;br /&gt;
This will create a clone of your current moodle development repository, with your plugins, in ~/moodleclone/moodle&lt;br /&gt;
Now, we&#039;ll use the &amp;lt;tt&amp;gt;git filter-branch&amp;lt;/tt&amp;gt; command to reduce this clone to just the plugin. &lt;br /&gt;
 cd ~/moodleclone/moodle&lt;br /&gt;
 git filter-branch --subdirectory-filter blocks/myblock/&lt;br /&gt;
The files from blocks/myblock/ will now be at the root of the repository. All other files will have been removed (this is why we&#039;re using a clone).&lt;br /&gt;
You can now track the plugin in it&#039;s own repository by cloning this reduced repository to a subdirectory of the new moodle clone.&lt;br /&gt;
 cd ~/newmoodle/blocks&lt;br /&gt;
 git clone ~/moodleclone/moodle myblock&lt;br /&gt;
This will clone the block&#039;s files, with the full history, into their own repository in the myblock subdirectory.&lt;br /&gt;
You can now delete ~/moodleclone/moodle, and repeat with any other plugins you&#039;ve developed.&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Git_repositories_for_contrib_modules&amp;diff=81930</id>
		<title>Git repositories for contrib modules</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Git_repositories_for_contrib_modules&amp;diff=81930"/>
		<updated>2011-03-15T09:28:46Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Created initial page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Managing contrib plugin with git makes it easy to make local modifications and pull in updates.&lt;br /&gt;
There are several options for managing a contrib plugin with git:&lt;br /&gt;
# Add the module to your main moodle git repository&lt;br /&gt;
# Create a self-contained repository for the plugin in a subdirectory&lt;br /&gt;
# Create a git submodule, which creates a repository for the plugin but tracks updates in the main repository too. It also allows you to clone the plugins with the main repository&lt;br /&gt;
Having used all of the above, the method I&#039;d recommend is number 2, as it&#039;s most convenient. The main disadvantage of 1 is that you can&#039;t easily pull in updates, and the main disadvantage of 3 is that you have to make each commit to the module twice.&lt;br /&gt;
&lt;br /&gt;
== Creating a new plugin ==&lt;br /&gt;
If you intend to publish the plugin, I highly recommend creating a [http://github.org github] repository from the start. This will allow you to publish with a single command when you&#039;re ready.  Just go to the site, sign up for an account, create a new repository. The naming convention for Moodle plugin repositories is &amp;lt;tt&amp;gt;moodle-plugintype_pluginname&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Github will give you instructions for cloning your (blank) repository. If you&#039;re using option 2 above, navigate to the directory for the plugin type you&#039;re developing (e.g. /block, /mod, /local) and run the &amp;lt;tt&amp;gt;git clone&amp;lt;/tt&amp;gt; command there. This will create a subdirectory called &amp;lt;tt&amp;gt;moodle-plugintype_pluginname&amp;lt;/tt&amp;gt;, rename this to &amp;lt;tt&amp;gt;pluginname&amp;lt;/tt&amp;gt; and you&#039;re good to go. &amp;lt;tt&amp;gt;cd&amp;lt;/tt&amp;gt; into this directory to perform git commands on this plugin&#039;s repository - outside of this directory will perform them on the main Moodle repository.&lt;br /&gt;
&lt;br /&gt;
You can then develop and test your changes locally, and when you&#039;re ready to publish, run&lt;br /&gt;
 git push origin&lt;br /&gt;
&lt;br /&gt;
== Installing a third-party plugin ==&lt;br /&gt;
Installing a plugin developed by a third party differs depending on whether they have used git or not.&lt;br /&gt;
If they have used git, you can follow the instructions above, but skip out the part where you create a new repository and clone their own git repository instead.&lt;br /&gt;
&lt;br /&gt;
If they haven&#039;t used git, you can still use git (and even github, if you like) to track local modifications to the plugin. Simply create a directory for the plugin&lt;br /&gt;
 mkdir ~/moodle/blocks/newblock&lt;br /&gt;
Initialise a new git repository there&lt;br /&gt;
 cd ~/moodle/blocks/newblock&lt;br /&gt;
 git init&lt;br /&gt;
unzip or copy the files to the repository&lt;br /&gt;
 cd ~&lt;br /&gt;
 tar -xf newblock.tar.gz&lt;br /&gt;
 cp newblock/* ~/moodle/blocks/newblock&lt;br /&gt;
add and commit the files&lt;br /&gt;
 cd ~/moodle/blocks/newblock&lt;br /&gt;
 git add .&lt;br /&gt;
 git commit . -m &amp;quot;Added files for newblock&amp;quot;&lt;br /&gt;
When installing updates, you&#039;ll need to copy the new files in place of the old one, and re run the &amp;lt;tt&amp;gt;git add&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;git commit&amp;lt;/tt&amp;gt; commands.&lt;br /&gt;
&lt;br /&gt;
== Moving a plugin to it&#039;s own repository ==&lt;br /&gt;
You may have developed a plugin within your main Moodle repository, but want to move it to a separate one to make it easier to publish.  Using &amp;lt;tt&amp;gt;git filter-branch&amp;lt;/tt&amp;gt;, we can achieve this and maintain all existing history for the plugin&#039;s files.&lt;br /&gt;
&lt;br /&gt;
First, you&#039;ll need a fresh copy of moodle (this will become your new moodle repository)&lt;br /&gt;
 mkdir ~/newmoodle&lt;br /&gt;
 cd ~/newmoodle&lt;br /&gt;
 git clone git://git.moodle.org/moodle.git&lt;br /&gt;
This will create a clone of Moodle without your plugins in ~/newmoodle/moodle&lt;br /&gt;
Next, you need to clone your local Moodle repository (why will become clear).&lt;br /&gt;
 mkdir ~/moodleclone&lt;br /&gt;
 cd ~/moodleclone&lt;br /&gt;
 git clone ~/moodle&lt;br /&gt;
This will create a clone of your current moodle development repository, with your plugins, in ~/moodleclone/moodle&lt;br /&gt;
Now, we&#039;ll use the &amp;lt;tt&amp;gt;git filter-branch&amp;lt;/tt&amp;gt; command to reduce this clone to just the plugin. &lt;br /&gt;
 cd ~/moodleclone/moodle&lt;br /&gt;
 git filter-branch --subdirectory-filter blocks/myblock/&lt;br /&gt;
The files from blocks/myblock/ will now be at the root of the repository. All other files will have been removed (this is why we&#039;re using a clone).&lt;br /&gt;
You can now track the plugin in it&#039;s own repository by cloning this reduced repository to a subdirectory of the new moodle clone.&lt;br /&gt;
 cd ~/newmoodle/blocks&lt;br /&gt;
 git clone ~/moodleclone/moodle myblock&lt;br /&gt;
This will clone the block&#039;s files, with the full history, into their own repository in the myblock subdirectory.&lt;br /&gt;
You can now delete ~/moodleclone/moodle, and repeat with any other plugins you&#039;ve developed.&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81927</id>
		<title>Maintaining Moodle customisations with Git</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Maintaining_Moodle_customisations_with_Git&amp;diff=81927"/>
		<updated>2011-03-15T08:56:07Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: New page: Git makes it very easy to maintain local customisations to Moodle alongside updates from the official Moodle repository. This page assumes you installed Moodle following [[Installing Moodl...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Git makes it very easy to maintain local customisations to Moodle alongside updates from the official Moodle repository.&lt;br /&gt;
This page assumes you installed Moodle following [[Installing Moodle from Git repository]]. It also assumes you understand basic version control principles (repositories, branches, conflicts) and have a basic working knowledge of Git.&lt;br /&gt;
&lt;br /&gt;
From your moodle directory, create a new branch for developing your customisation, and move to that branch:&lt;br /&gt;
 git branch myfeature&lt;br /&gt;
 git checkout myfeature&lt;br /&gt;
&lt;br /&gt;
 Switched to branch &#039;myfeature&#039;&lt;br /&gt;
This will give you a seperate copy of the Moodle code to work on without affecting the master branch. It&#039;s not recommended that you do this on your production server, as it will cause the code to be available immediately as it&#039;s saved.&lt;br /&gt;
&lt;br /&gt;
Do your customisations, add any new files to git, and commit the changes&lt;br /&gt;
 git add .&lt;br /&gt;
 git commit . -m &amp;quot;Description of the change&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Switch back to the master branch and merge the changes&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git merge myfeature&lt;br /&gt;
Any future development can take place on the myfeature branch, and be merged into master in this way&lt;br /&gt;
&lt;br /&gt;
Even after local modifications have been made, you can pull in updates from the official git repository&lt;br /&gt;
 git checkout master&lt;br /&gt;
 git fetch&lt;br /&gt;
 git merge origin/master&lt;br /&gt;
&lt;br /&gt;
=== Conflicts ===&lt;br /&gt;
If you create a local modification to a file, and that same file is modified in the official repository, you may find that a conflict is created when you do &amp;lt;tt&amp;gt;git merge origin/master&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To resolve this, you will need to find the conflicts (the attempt to merge will tell you where they are) and resolve them.  The [http://www.kernel.org/pub/software/scm/git/docs/git-merge.html|&amp;lt;tt&amp;gt;git merge&amp;lt;/tt&amp;gt; man page] has more information on the presentation and resolution of conflicts.&lt;br /&gt;
&lt;br /&gt;
After the conflict is resolved, you&#039;ll need to commit the resolved files.&lt;br /&gt;
 git commit -a&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Installing_Moodle_from_Git_repository&amp;diff=81926</id>
		<title>Installing Moodle from Git repository</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Installing_Moodle_from_Git_repository&amp;diff=81926"/>
		<updated>2011-03-15T08:42:26Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* Linux/Unix command line */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Linux/Unix command line ==&lt;br /&gt;
These instructions should be very similar on Windows.&lt;br /&gt;
&lt;br /&gt;
Move to the directory where you wish to install Moodle. Moodle will go in ./moodle, relative to this directory&lt;br /&gt;
 cd ~&lt;br /&gt;
Clone the offical Moodle repository via git&lt;br /&gt;
 git clone git://git.moodle.org/moodle.git&lt;br /&gt;
If you have firewall issues with the git protocol, the above may not work, in which case you can try cloning the official github repository via http&lt;br /&gt;
 git clone https://github.com/moodle/moodle.git&lt;br /&gt;
&lt;br /&gt;
 Initialized empty Git repository in ~/moodle/.git/&lt;br /&gt;
 remote: Counting objects: 448351, done.&lt;br /&gt;
 remote: Compressing objects: 100% (103262/103262), done.&lt;br /&gt;
 remote: Total 448351 (delta 336929), reused 446784 (delta 335924)&lt;br /&gt;
 Receiving objects: 100% (448351/448351), 128.54 MiB | 10.94 MiB/s, done.&lt;br /&gt;
 Resolving deltas: 100% (336929/336929), done.&lt;br /&gt;
Move in to the new moodle directory (you can rename this if you wish)&lt;br /&gt;
 cd moodle&lt;br /&gt;
From here, you can edit config.php and install as per the [[Installing_Moodle#Setting-up_your_web_server|Installation Instructions]]&lt;br /&gt;
Upgrading to the latest Moodle version is now 2 simple commands:&lt;br /&gt;
 git fetch&lt;br /&gt;
 git merge origin/master&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Installing_Moodle_from_Git_repository&amp;diff=81925</id>
		<title>Installing Moodle from Git repository</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Installing_Moodle_from_Git_repository&amp;diff=81925"/>
		<updated>2011-03-15T08:40:56Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Initial draft of instructions&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Linux/Unix command line ==&lt;br /&gt;
These instructions should be very similar on Windows.&lt;br /&gt;
&lt;br /&gt;
Move to the directory where you wish to install Moodle. Moodle will go in ./moodle, relative to this directory&lt;br /&gt;
 cd ~&lt;br /&gt;
Clone the offical Moodle repository via git&lt;br /&gt;
 git clone git://git.moodle.org/moodle.git&lt;br /&gt;
If you have firewall issues with the git protocol, the above may not work, in which case you can try cloning the official github repository via http&lt;br /&gt;
 git clone https://github.com/moodle/moodle.git&lt;br /&gt;
&lt;br /&gt;
 Initialized empty Git repository in ~/moodle/.git/&lt;br /&gt;
 remote: Counting objects: 448351, done.&lt;br /&gt;
 remote: Compressing objects: 100% (103262/103262), done.&lt;br /&gt;
 remote: Total 448351 (delta 336929), reused 446784 (delta 335924)&lt;br /&gt;
 Receiving objects: 100% (448351/448351), 128.54 MiB | 10.94 MiB/s, done.&lt;br /&gt;
 Resolving deltas: 100% (336929/336929), done.&lt;br /&gt;
Move in to the new moodle directory (you can rename this if you wish)&lt;br /&gt;
 cd moodle&lt;br /&gt;
From here, you can edit config.php and install as per the [[Installing_Moodle#Setting-up_your_web_server|Installation Instructions]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Git&amp;diff=81924</id>
		<title>Git</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Git&amp;diff=81924"/>
		<updated>2011-03-15T08:28:06Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* Moodle specific guides */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[http://git-scm.com/ Git] is a free and open source version control system. Git is a more sophisticated replacement for [[CVS]]. You can find the official Git Moodle repository at http://git.moodle.org/ or mirror at https://github.com/moodle/moodle. The particular advantage of Git is its distributed model, making it ideal for managing local customisations to Moodle. It is also suitable for development of contrib plugins for Moodle.&lt;br /&gt;
&lt;br /&gt;
Use the &#039;&#039;Git&#039;&#039; category link at the end of this page to get a list of all Git related pages.&lt;br /&gt;
&lt;br /&gt;
==Books and tutorials==&lt;br /&gt;
* [http://progit.org/ Pro Git Book]&lt;br /&gt;
* [http://book.git-scm.com/ Git Community Book]&lt;br /&gt;
* [http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html Official Git tutorial]&lt;br /&gt;
* [http://help.github.com/ GitHub Help]&lt;br /&gt;
&lt;br /&gt;
==Moodle specific guides==&lt;br /&gt;
* [[Installing Moodle from Git repository]] - WIP&lt;br /&gt;
* [[Maintaining Moodle customisations with Git]] - WIP&lt;br /&gt;
* Submitting patches and pull requests - TODO&lt;br /&gt;
* [[Git repositories for contrib modules]] - WIP&lt;br /&gt;
&lt;br /&gt;
==Tools==&lt;br /&gt;
The most powerful tool you can git is probably command line git. If you prefer clicking you can try one of the following, more information at [http://git-scm.com/tools http://git-scm.com/tools].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;IDE integrations&#039;&#039;&#039;&lt;br /&gt;
* [http://www.eclipse.org/egit/ EGit plugin for Eclipse IDE]&lt;br /&gt;
* [http://netbeans.org/projects/versioncontrol/pages/Git_main Netbeans] - early access official Git plugin for Netbeans&lt;br /&gt;
* [http://www.jetbrains.com/phpstorm/ PHPStorm] - commercial IDE with Git support&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Frontends&#039;&#039;&#039;&lt;br /&gt;
* [http://code.google.com/p/tortoisegit/ TortoiseGit] - Windows only UI&lt;br /&gt;
* [http://gitx.frim.nl/ GitX] - OS X only UI&lt;br /&gt;
* [http://www.syntevo.com/smartgit/index.html SmartGit] - feature rich multiplatform UI (free for non-commercial use)&lt;br /&gt;
&lt;br /&gt;
==Hosting==&lt;br /&gt;
* [http://github GitHub] - probably the best hosting choice for beginners&lt;br /&gt;
* [http://gitorious.org/ Gitorious] - free hosting running on open source code&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:Git Migration]]&lt;br /&gt;
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=162723 Moving from CVS to git in November 2010] forum discussion&lt;br /&gt;
&lt;br /&gt;
[[Category:Git]]&lt;br /&gt;
[[Category:Administrator]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Javascript_FAQ&amp;diff=81151</id>
		<title>Javascript FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Javascript_FAQ&amp;diff=81151"/>
		<updated>2011-02-08T14:37:40Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is JavaScript? ==&lt;br /&gt;
&lt;br /&gt;
JavaScript is a scripting language widely used for client-side web development.&lt;br /&gt;
&lt;br /&gt;
== Where do I find general information about JavaScript? ==&lt;br /&gt;
&lt;br /&gt;
=== Online resources: ===&lt;br /&gt;
* [http://en.wikipedia.org/wiki/JavaScript JavaScript (Wikipedia)]&lt;br /&gt;
* [http://www.w3schools.com/JS/ JavaScript Tutorial] at W3Schools.com&lt;br /&gt;
* [http://articles.sitepoint.com/category/javascript Sitepoint JavaScript tutorials]&lt;br /&gt;
&lt;br /&gt;
=== Books: ===&lt;br /&gt;
* [http://oreilly.com/catalog/9780596101992 JavaScript: The Definitive Guide, Fifth Edition] by David Flanagan - Really the ultimate reference guide (nearly 1000 pages).&lt;br /&gt;
* [http://www.sitepoint.com/books/jsant1/ The JavaScript Anthology: 101 Essential Tips, Tricks &amp;amp; Hacks] by James Edwards &amp;amp; Cameron Adams - Promotes accessible JavaScript solutions by following the principles of [[Development:Progressive enhancement| progressive enhancement]] and [[Development:Unobtrusive_Javascript| unobtrusive scripting]].&lt;br /&gt;
&lt;br /&gt;
== How is JavaScript used by Moodle? ==&lt;br /&gt;
&lt;br /&gt;
* See [https://docs.moodle.org/en/Category:Javascript Category:Javascript].&lt;br /&gt;
&lt;br /&gt;
== Where do I find more information about JavaScript in Moodle? ==&lt;br /&gt;
&lt;br /&gt;
* [[Development:JavaScript_guidelines|JavaScript Guidelines]] by Tim Hunt (work in progress)&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=106312 Use of JavaScript in Moodle] discussion in the General developer forum&lt;br /&gt;
&lt;br /&gt;
== What JavaScript library does Moodle use? ==&lt;br /&gt;
&lt;br /&gt;
=== Yahoo! User Interface Library (YUI) === &lt;br /&gt;
Moodle uses the Yahoo! User Interface Library (YUI).&lt;br /&gt;
&lt;br /&gt;
==== Online resources: ====&lt;br /&gt;
* [http://developer.yahoo.com/yui/ Yahoo! User Interface Library (YUI)]&lt;br /&gt;
* [[Development:YUI]] in the Moodle documentation&lt;br /&gt;
&lt;br /&gt;
==== Books: ====&lt;br /&gt;
* [http://www.packtpub.com/yahoo!-user-interface-library-yui/book Learning the Yahoo! User Interface Library] by Dan Wellman&lt;br /&gt;
&lt;br /&gt;
==== How/Why was YUI chosen for Moodle? ====&lt;br /&gt;
&lt;br /&gt;
The decision was made in [http://moodle.org/mod/forum/discuss.php?d=48478 this thread in the General Developer Forum].&lt;br /&gt;
&lt;br /&gt;
==== yui_module function in Moodle 2.0 ====&lt;br /&gt;
See [http://moodle.org/mod/forum/discuss.php?d=154359 JavaScript Cache and YUI Modules] and MDL-22920.&lt;br /&gt;
&lt;br /&gt;
== What other JavaScript libraries are around? ==&lt;br /&gt;
&lt;br /&gt;
* A nice comparison chart: [http://wiki.freaks-unidos.net/javascript-libraries Evaluation of JavaScript Libraries]&lt;br /&gt;
&lt;br /&gt;
=== jQuery ===&lt;br /&gt;
&lt;br /&gt;
jQuery is another popular JavaScript library, used among others by Drupal, Joomla and WordPress.&lt;br /&gt;
&lt;br /&gt;
==== Online resources: ====&lt;br /&gt;
* [http://jquery.com/ jQuery] &lt;br /&gt;
* [http://visualjquery.com Visual jQuery]&lt;br /&gt;
* [http://jqueryfordesigners.com jQuery for Designers]&lt;br /&gt;
&lt;br /&gt;
==== Books: ====&lt;br /&gt;
* [http://www.manning.com/bibeault/ jQuery in Action] by Bear Bibeault and Yehuda Katz&lt;br /&gt;
* [http://www.packtpub.com/jQuery/book Learning jQuery] by Karl Swedberg and Jonathan Chaffer&lt;br /&gt;
* [http://www.packtpub.com/jquery-reference-guide-Open-Source/book jQuery Reference Guide] by Jonathan Chaffer and Karl Swedberg&lt;br /&gt;
&lt;br /&gt;
== What does AJAX mean? ==&lt;br /&gt;
AJAX means &amp;quot;Asynchronous JavaScript and XML&amp;quot;. It is a group of interrelated web development techniques used to create interactive web applications or rich Internet applications.&lt;br /&gt;
&lt;br /&gt;
See [http://en.wikipedia.org/wiki/Ajax_(programming) AJAX (Wikipedia)] for general information and [[AJAX]] for information on AJAX and Moodle.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[User:Frank_Ralf/JavaScript1]] compares different solutions (plain JavaScript, YUI, and jQuery) to a simple enhancement to a form.&lt;br /&gt;
* [[Development:Using jQuery with Moodle 2.0]]&lt;br /&gt;
* [[Javascript and YUI 3 FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
[[Category:Javascript]]&lt;br /&gt;
[[Category:AJAX]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:How_to_create_a_YUI_3_module&amp;diff=81147</id>
		<title>Development:How to create a YUI 3 module</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:How_to_create_a_YUI_3_module&amp;diff=81147"/>
		<updated>2011-02-08T14:01:10Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* What else to read */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}This document explains how to create a YUI 3 module in Moodle.&lt;br /&gt;
&lt;br /&gt;
= The two ways to write a YUI 3 module =&lt;br /&gt;
There is two ways to write a YUI 3 module. The two following paragraphs are sourced from a chat with Sam Hemelryk.&lt;br /&gt;
==The static module==&lt;br /&gt;
The static module is the simpler of the two, in this case you simply put your code into a module.js file within your plugin. Into that file you create a namespace and define any functions or objects you want to use.&lt;br /&gt;
&lt;br /&gt;
Within PHP static modules are also pretty easy to use. The first step if to create a module definition which tells moodle what your module is called, what it requires, and can optionally give it strings.&lt;br /&gt;
&lt;br /&gt;
Once the module is defined you can then use any of the several JS methods for including JS in your page and pass your module definition along.&lt;br /&gt;
&lt;br /&gt;
Whilst this method is simpler to write and understand especially when you are first starting out with JavaScript it isn&#039;t as easily flexible and has some quirks that you need will need to overcome, especially with more complex JavaScript.&lt;br /&gt;
&lt;br /&gt;
This method of writing a module should be used if you are just starting out with JavaScript or if the JS solution you are creating is going to be relatively simple in nature.&lt;br /&gt;
If you are writing something more complex I would strongly suggest looking at the other method as it will result in cleaner, easier to read code at the end of the day. However it will require you to learn your way around writing a Moodle module.&lt;br /&gt;
&lt;br /&gt;
==The YUI3 Moodle Module==&lt;br /&gt;
This method is certainly more complex than the previous method however it is much more flexible and when you have learnt and understand what you are doing it is much quicker to write and more versatile as well. These modules can also easily include other YUI3 Moodle modules, and can choose to include module specific CSS as well.&lt;br /&gt;
&lt;br /&gt;
In this method you create a &#039;&#039;&#039;yui&#039;&#039;&#039; directory within you plugin directory, and then sub directories for each module you wish to write, you name them the same as you want your module named.&lt;br /&gt;
Into the subdirectory you create a JavaScript file with the same name that you gave the subdirectory, e.g.&#039;&#039;&#039;/local/myplugin/yui/mymodule/mymodule.js&#039;&#039;&#039;&lt;br /&gt;
The JS that you then put into this file should then be written in the same way you would write a YUI module, before you ask it certainly requires a good understanding of YUI.&lt;br /&gt;
&lt;br /&gt;
I would recommend this method of writing a module providing you either have an understanding of how to write a YUI module, or you are happy to learn. It normally results in cleaner easier to read code, and if desired can easily be written in such as way as to make it VERY easy to re-use in other bits of code.... particularly helpful if you have several JavaScript objects in play at a time.&lt;br /&gt;
&lt;br /&gt;
= Static module quick start = &lt;br /&gt;
1. Create a module.js file somewhere &lt;br /&gt;
&lt;br /&gt;
2. The two ways Moodle can load this file are:&lt;br /&gt;
&lt;br /&gt;
a- the file is in core: declare the file into /lib/outputrequirementslib.php/find_module($component)&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
          //example:&lt;br /&gt;
          case &#039;core_rating&#039;:&lt;br /&gt;
                    $module = array(&#039;name&#039;     =&amp;gt; &#039;core_rating&#039;,&lt;br /&gt;
                                    &#039;fullpath&#039; =&amp;gt; &#039;/rating/module.js&#039;,&lt;br /&gt;
                                    &#039;requires&#039; =&amp;gt; array(&#039;node&#039;, &#039;event&#039;, &#039;overlay&#039;, &#039;io&#039;, &#039;json&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
b- the file is in a local plugin: the first line of your module should be&lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
 M.local_xxx = {&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
xxx being your plugin directory name.&lt;br /&gt;
&lt;br /&gt;
3. Write the module.js&lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
  M.local_hub={&lt;br /&gt;
    Y : null,&lt;br /&gt;
    transaction : [],&lt;br /&gt;
    init : function(Y){&lt;br /&gt;
        alert(&#039;hub module initialisation&#039;);&lt;br /&gt;
        this.Y = Y;&lt;br /&gt;
    },&lt;br /&gt;
  }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
4. Call this module. It can not be in a php renderer script. However you could call it where you call the renderer.&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
    $PAGE-&amp;gt;requires-&amp;gt;js_init_call(&#039;M.local_hub.init&#039;); &lt;br /&gt;
You should now have loaded and called your first YUI 3 module in Moodle.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
5. If you want to load your module with some other YUI modules&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
    $jsmodule = array(&lt;br /&gt;
                &#039;name&#039; =&amp;gt; &#039;local_hub&#039;,&lt;br /&gt;
                &#039;fullpath&#039; =&amp;gt; &#039;/local/hub/module.js&#039;,&lt;br /&gt;
                &#039;requires&#039; =&amp;gt; array(&amp;quot;overlay&amp;quot;, &amp;quot;anim&amp;quot;, &amp;quot;plugin&amp;quot;)); //on this line you are loading three other YUI modules&lt;br /&gt;
    $PAGE-&amp;gt;requires-&amp;gt;js_init_call(&#039;M.local_hub.init&#039;,&lt;br /&gt;
                 null, false, $jsmodule);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
6. If you want to pass parameter to the init function&lt;br /&gt;
&lt;br /&gt;
PHP:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
    $PAGE-&amp;gt;requires-&amp;gt;js_init_call(&#039;M.local_hub.init&#039;,&lt;br /&gt;
                    array(&#039;this is the param1 value&#039;), false, $jsmodule);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
JS:&lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
    init : function(Y, params){&lt;br /&gt;
        alert(params);&lt;br /&gt;
        ....&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
7. Then you should be able to fill the module with your own YUI javascript from [http://developer.yahoo.com/yui/3/examples/ YUI examples].&lt;br /&gt;
&lt;br /&gt;
= YUI 3 Moodle Module quick start =&lt;br /&gt;
1. Create the module_name.js file in /local/pluginname/yui/module_name/modulename.js or in /mod/modname/yui/modulename/modulename.js&lt;br /&gt;
&lt;br /&gt;
2. The basic module_name.js structure is:&lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
  YUI.add(&#039;moodle-local_pluginname-modulename&#039;, function(Y) {&lt;br /&gt;
    var ModulenameNAME = &#039;this_is_a_module_name&#039;;&lt;br /&gt;
    var MODULENAME = function() {&lt;br /&gt;
        MODULENAME.superclass.constructor.apply(this, arguments);&lt;br /&gt;
    }&lt;br /&gt;
    Y.extend(MODULENAME, Y.Base, {&lt;br /&gt;
        initializer : function(config) { //&#039;config&#039; contains the parameter values&lt;br /&gt;
            alert(&#039;I am in initializer&#039;);&lt;br /&gt;
        }&lt;br /&gt;
    }, {&lt;br /&gt;
        NAME : ModulenameNAME, //module name is something mandatory. &lt;br /&gt;
                                //It should be in lower case without space &lt;br /&gt;
                                //as YUI use it for name space sometimes.&lt;br /&gt;
        ATTRS : {&lt;br /&gt;
                 aparam : {}&lt;br /&gt;
        } // Attributs are the parameters sent when the $PAGE-&amp;gt;requires-&amp;gt;yui_module calls the module. &lt;br /&gt;
          // Here you can declare default values or run functions on the parameter. &lt;br /&gt;
          // The param names must be the same as the ones declared &lt;br /&gt;
          // in the $PAGE-&amp;gt;requires-&amp;gt;yui_module call.&lt;br /&gt;
    });&lt;br /&gt;
    M.local_pluginname = M.local_pluginname || {}; //this line use existing name path if it exists, ortherwise create a new one. &lt;br /&gt;
                                                 //This is to avoid to overwrite previously loaded module with same name.&lt;br /&gt;
    M.local_pluginname.init_modulename = function(config) { //&#039;config&#039; contains the parameter values&lt;br /&gt;
        alert(&#039;I am in the javascript module, Yeah!&#039;);&lt;br /&gt;
        return new MODULENAME(config); //&#039;config&#039; contains the parameter values&lt;br /&gt;
    }&lt;br /&gt;
  }, &#039;@VERSION@&#039;, {&lt;br /&gt;
      requires:[&#039;base&#039;,&#039;another_required_YUI_module&#039;, &#039;a_moodle_YUI_module&#039;]&lt;br /&gt;
  });&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
3. Call the javascript in PHP (if you copied the previous javascript, 2 javascript alert should appear.)&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
  $PAGE-&amp;gt;requires-&amp;gt;yui_module(&#039;moodle-local_pluginname-modulename&#039;, &#039;M.local_pluginname.init_modulename&#039;,&lt;br /&gt;
                array(array(&#039;aparam&#039;=&amp;gt;&#039;paramvalue&#039;)));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
== Full simple example==&lt;br /&gt;
Once you understand and run the above quick start, here is simple YUI 3 example. It shows how to use another YUI 3 module in your module, and to use some events.&lt;br /&gt;
=== It includes===&lt;br /&gt;
* display a parameter value in two javascript alert boxes =&amp;gt; demonstrate how to pass a param to the initialize function in two different ways&lt;br /&gt;
* display an overlay when you click on an image&lt;br /&gt;
* hide the overlay when you click on the body&lt;br /&gt;
* some commented code to see how Moodle YUI exception works&lt;br /&gt;
&lt;br /&gt;
=== PHP ===&lt;br /&gt;
Create a [https://docs.moodle.org/en/Development:Local_customisation basic local plugin] (in this example it is named hub) in /local/hub/ and add this code into one of the plugin pages:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
   $PAGE-&amp;gt;requires-&amp;gt;yui_module(&#039;moodle-local_hub-comments&#039;, &#039;M.local_hub.init_comments&#039;,&lt;br /&gt;
                array(array(&#039;commentids&#039; =&amp;gt; &#039;1 , 23 ,45&#039;)));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== HTML ===&lt;br /&gt;
The plugin page should generate this HTML code:&lt;br /&gt;
&amp;lt;code xml&amp;gt;&lt;br /&gt;
&amp;lt;!-- image to click on --&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;comments&amp;quot;&amp;gt;&amp;lt;img src=&#039;http://moodle.org/theme/moodle2/pix/moodle-logo.gif&#039; alt=&#039;the image to click on&#039;/&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- overlay --&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;commentoverlay&amp;quot; class=&amp;quot;yui3-overlay-loading&amp;quot;&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;yui3-widget-hd&amp;quot;&amp;gt;Comment&amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;yui3-widget-bd&amp;quot;&amp;gt;this is a comment&amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;div class=&amp;quot;yui3-widget-bd&amp;quot;&amp;gt;this is another comment&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== CSS ===&lt;br /&gt;
The plugin style.css should contain:&lt;br /&gt;
&amp;lt;code css&amp;gt;&lt;br /&gt;
/* Hide overlay markup while loading, if js is enabled */&lt;br /&gt;
.yui3-js-enabled .yui3-overlay-loading {&lt;br /&gt;
    top:-1000em;&lt;br /&gt;
    left:-1000em;&lt;br /&gt;
    position:absolute;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/* Overlay Look/Feel */&lt;br /&gt;
.yui3-overlay-content {&lt;br /&gt;
    padding:3px;&lt;br /&gt;
    border:1px solid #000;&lt;br /&gt;
    background-color:#aaa;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.yui3-overlay-content .yui3-widget-hd {&lt;br /&gt;
    padding:5px;&lt;br /&gt;
    border:2px solid #aa0000;&lt;br /&gt;
    background-color:#fff;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.yui3-overlay-content .yui3-widget-bd {&lt;br /&gt;
    padding:5px;&lt;br /&gt;
    border:2px solid #0000aa;&lt;br /&gt;
    background-color:#fff;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== JS ===&lt;br /&gt;
In /local/hub/yui/comments/comments.js&lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
YUI.add(&#039;moodle-local_hub-comments&#039;, function(Y) {&lt;br /&gt;
&lt;br /&gt;
    var COMMENTSNAME = &#039;hub_comments&#039;;&lt;br /&gt;
&lt;br /&gt;
    //we declare the overlay here so it&#039;s accessible to all the extended class function&#039;&lt;br /&gt;
    var overlay = new Y.Overlay({&lt;br /&gt;
                srcNode:&amp;quot;#commentoverlay&amp;quot;, //the main div with id = commentoverlay&lt;br /&gt;
                width:&amp;quot;10em&amp;quot;,&lt;br /&gt;
                height:&amp;quot;10em&amp;quot;,&lt;br /&gt;
                xy:[ 0, 0],&lt;br /&gt;
                visible: false //by default it is not displayed&lt;br /&gt;
            });&lt;br /&gt;
&lt;br /&gt;
    var COMMENTS = function() {&lt;br /&gt;
        COMMENTS.superclass.constructor.apply(this, arguments);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Y.extend(COMMENTS, Y.Base, {&lt;br /&gt;
&lt;br /&gt;
        event:null,&lt;br /&gt;
&lt;br /&gt;
        initializer : function(params) {&lt;br /&gt;
&lt;br /&gt;
            //Example how to retrieve the parameter,&lt;br /&gt;
            //see what happens if you don&#039;t pass the parameter in the call&lt;br /&gt;
            alert(this.get(&#039;commentids&#039;)); // You usually use an attribute because&lt;br /&gt;
                                           //a attribut can have default value.&lt;br /&gt;
                                           //use the ATTRS default value if not passed as parameter&lt;br /&gt;
            alert(params.commentids); // undefined if not passed as parameter&lt;br /&gt;
&lt;br /&gt;
            //render the overlay&lt;br /&gt;
            overlay.render();&lt;br /&gt;
&lt;br /&gt;
            // position the overlay in the middle of the web browser window&lt;br /&gt;
            var WidgetPositionAlign = Y.WidgetPositionAlign;&lt;br /&gt;
            overlay.set(&amp;quot;align&amp;quot;, {&lt;br /&gt;
                node:&amp;quot;&amp;quot;, //empty =&amp;gt; viewport&lt;br /&gt;
                points:[WidgetPositionAlign.CC, WidgetPositionAlign.CC]&lt;br /&gt;
            });&lt;br /&gt;
&lt;br /&gt;
            //attach a show event on the div with id = comments&lt;br /&gt;
            //we also change the div style to display the click zone&lt;br /&gt;
            Y.one(&#039;#comments&#039;).setStyle(&amp;quot;border&amp;quot;, &amp;quot;1px solid red&amp;quot;).on(&#039;click&#039;, this.show, this);&lt;br /&gt;
&lt;br /&gt;
            //uncomment the try content to see how works exception in Moodle&lt;br /&gt;
            //this exception has been specially created for Moodle&lt;br /&gt;
            try {&lt;br /&gt;
              //surely_not_existing_js_function();&lt;br /&gt;
            } catch (exception) {&lt;br /&gt;
                new M.core.exception(exception);&lt;br /&gt;
            }&lt;br /&gt;
&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
        show : function (e) {&lt;br /&gt;
            overlay.show(); //show the overlay&lt;br /&gt;
           &lt;br /&gt;
            e.halt(); // we are going to attach a new &#039;hide overlay&#039; event to the body,&lt;br /&gt;
                      // because javascript always propagate event to parent tag,&lt;br /&gt;
                      // we need to tell Yahoo to stop to call the event on parent tag&lt;br /&gt;
                      // otherwise the hide event will be call right away.&lt;br /&gt;
&lt;br /&gt;
            //we add a new event on the body in order to hide the overlay for the next click&lt;br /&gt;
            this.event = Y.one(document.body).on(&#039;click&#039;,this.hide,this);&lt;br /&gt;
        },&lt;br /&gt;
&lt;br /&gt;
        hide : function () {&lt;br /&gt;
            overlay.hide(); //hide the overlay&lt;br /&gt;
            this.event.detach(); //we need to detach the hide event&lt;br /&gt;
                                 //Note: it would work without but create js warning everytime&lt;br /&gt;
                                 //we click on the body&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
    }, {&lt;br /&gt;
        NAME : COMMENTSNAME,&lt;br /&gt;
        ATTRS : {&lt;br /&gt;
            commentids: {value : 450} //default value (has no purpose in this code except to show you&lt;br /&gt;
                                      // how to pass/use a param value)&lt;br /&gt;
        }&lt;br /&gt;
    });&lt;br /&gt;
&lt;br /&gt;
    M.local_hub = M.local_hub || {};&lt;br /&gt;
    M.local_hub.init_comments = function(params) {&lt;br /&gt;
        return new COMMENTS(params);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
}, &#039;@VERSION@&#039;, {&lt;br /&gt;
    requires:[&#039;base&#039;,&#039;overlay&#039;, &#039;moodle-enrol-notification&#039;]&lt;br /&gt;
    //Note: &#039;moodle-enrol-notification&#039; contains Moodle YUI exception&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= What else to read =&lt;br /&gt;
Two pages are important to start with when you discover YUI 3&lt;br /&gt;
* you should read the [http://developer.yahoo.com/yui/3/base/ base YUI doc]. It is very useful to understand the YUI 3 Moodle module.&lt;br /&gt;
* you want to have a look to the [http://developer.yahoo.com/yui/3/examples/ YUI 3 examples]. Always open the examples in a window to have a look to the complete example codes.&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer]]&lt;br /&gt;
[[Category:AJAX]]&lt;br /&gt;
[[Category:Javascript]]&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
[[Javascript and YUI 3 FAQ]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Javascript_FAQ&amp;diff=81145</id>
		<title>Javascript FAQ</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Javascript_FAQ&amp;diff=81145"/>
		<updated>2011-02-08T14:00:42Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is JavaScript? ==&lt;br /&gt;
&lt;br /&gt;
JavaScript is a scripting language widely used for client-side web development.&lt;br /&gt;
&lt;br /&gt;
== Where do I find general information about JavaScript? ==&lt;br /&gt;
&lt;br /&gt;
=== Online resources: ===&lt;br /&gt;
* [http://en.wikipedia.org/wiki/JavaScript JavaScript (Wikipedia)]&lt;br /&gt;
* [http://www.w3schools.com/JS/ JavaScript Tutorial] at W3Schools.com&lt;br /&gt;
* [http://articles.sitepoint.com/category/javascript Sitepoint JavaScript tutorials]&lt;br /&gt;
&lt;br /&gt;
=== Books: ===&lt;br /&gt;
* [http://oreilly.com/catalog/9780596101992 JavaScript: The Definitive Guide, Fifth Edition] by David Flanagan - Really the ultimate reference guide (nearly 1000 pages).&lt;br /&gt;
* [http://www.sitepoint.com/books/jsant1/ The JavaScript Anthology: 101 Essential Tips, Tricks &amp;amp; Hacks] by James Edwards &amp;amp; Cameron Adams - Promotes accessible JavaScript solutions by following the principles of [[Development:Progressive enhancement| progressive enhancement]] and [[Development:Unobtrusive_Javascript| unobtrusive scripting]].&lt;br /&gt;
&lt;br /&gt;
== How is JavaScript used by Moodle? ==&lt;br /&gt;
&lt;br /&gt;
* See [https://docs.moodle.org/en/Category:Javascript Category:Javascript].&lt;br /&gt;
&lt;br /&gt;
== Where do I find more information about JavaScript in Moodle? ==&lt;br /&gt;
&lt;br /&gt;
* [[Development:JavaScript_guidelines|JavaScript Guidelines]] by Tim Hunt (work in progress)&lt;br /&gt;
* [http://moodle.org/mod/forum/discuss.php?d=106312 Use of JavaScript in Moodle] discussion in the General developer forum&lt;br /&gt;
&lt;br /&gt;
== What JavaScript library does Moodle use? ==&lt;br /&gt;
&lt;br /&gt;
=== Yahoo! User Interface Library (YUI) === &lt;br /&gt;
Moodle uses the Yahoo! User Interface Library (YUI).&lt;br /&gt;
&lt;br /&gt;
==== Online resources: ====&lt;br /&gt;
* [http://developer.yahoo.com/yui/ Yahoo! User Interface Library (YUI)]&lt;br /&gt;
* [[Development:YUI]] in the Moodle documentation&lt;br /&gt;
&lt;br /&gt;
==== Books: ====&lt;br /&gt;
* [http://www.packtpub.com/yahoo!-user-interface-library-yui/book Learning the Yahoo! User Interface Library] by Dan Wellman&lt;br /&gt;
&lt;br /&gt;
==== How/Why was YUI chosen for Moodle? ====&lt;br /&gt;
&lt;br /&gt;
The decision was made in [http://moodle.org/mod/forum/discuss.php?d=48478 this thread in the General Developer Forum].&lt;br /&gt;
&lt;br /&gt;
==== yui_module function in Moodle 2.0 ====&lt;br /&gt;
See [http://moodle.org/mod/forum/discuss.php?d=154359 JavaScript Cache and YUI Modules] and MDL-22920.&lt;br /&gt;
&lt;br /&gt;
== What other JavaScript libraries are around? ==&lt;br /&gt;
&lt;br /&gt;
* A nice comparison chart: [http://wiki.freaks-unidos.net/javascript-libraries Evaluation of JavaScript Libraries]&lt;br /&gt;
&lt;br /&gt;
=== jQuery ===&lt;br /&gt;
&lt;br /&gt;
jQuery is another popular JavaScript library, used among others by Drupal, Joomla and WordPress.&lt;br /&gt;
&lt;br /&gt;
==== Online resources: ====&lt;br /&gt;
* [http://jquery.com/ jQuery] &lt;br /&gt;
* [http://visualjquery.com Visual jQuery]&lt;br /&gt;
* [http://jqueryfordesigners.com jQuery for Designers]&lt;br /&gt;
&lt;br /&gt;
==== Books: ====&lt;br /&gt;
* [http://www.manning.com/bibeault/ jQuery in Action] by Bear Bibeault and Yehuda Katz&lt;br /&gt;
* [http://www.packtpub.com/jQuery/book Learning jQuery] by Karl Swedberg and Jonathan Chaffer&lt;br /&gt;
* [http://www.packtpub.com/jquery-reference-guide-Open-Source/book jQuery Reference Guide] by Jonathan Chaffer and Karl Swedberg&lt;br /&gt;
&lt;br /&gt;
== What does AJAX mean? ==&lt;br /&gt;
AJAX means &amp;quot;Asynchronous JavaScript and XML&amp;quot;. It is a group of interrelated web development techniques used to create interactive web applications or rich Internet applications.&lt;br /&gt;
&lt;br /&gt;
See [http://en.wikipedia.org/wiki/Ajax_(programming) AJAX (Wikipedia)] for general information and [[AJAX]] for information on AJAX and Moodle.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[User:Frank_Ralf/JavaScript1]] compares different solutions (plain JavaScript, YUI, and jQuery) to a simple enhancement to a form.&lt;br /&gt;
* [[Development:Using jQuery with Moodle 2.0]]&lt;br /&gt;
&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
[[Category:Javascript]]&lt;br /&gt;
[[Javascript and YUI 3 FAQ]]&lt;br /&gt;
[[Category:AJAX]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:JavaScript_guidelines&amp;diff=81144</id>
		<title>Development:JavaScript guidelines</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:JavaScript_guidelines&amp;diff=81144"/>
		<updated>2011-02-08T14:00:13Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* See also */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
These guidelines can only be applied fully from Moodle 2.0 onwards, because they rely on our new API to facilitate use of JavaScript.&lt;br /&gt;
&lt;br /&gt;
When writing JavaScript for earlier versions of Moodle, please try to follow these guidelines in spirit and use the &#039;&#039;&#039;require_js&#039;&#039;&#039; function in place of $PAGE-&amp;gt;requires-&amp;gt;js_module/yui2_lib.&lt;br /&gt;
&lt;br /&gt;
==General principles==&lt;br /&gt;
&lt;br /&gt;
===Moodle should be usable without JavaScript===&lt;br /&gt;
&lt;br /&gt;
Everything in Moodle should work with JavaScript turned off. This is important for accessibility, and in line with the principles of [[Development:Unobtrusive_Javascript|unobtrusive JavaScript]] and [[Development:Progressive_enhancement|progressive enhancement]].&lt;br /&gt;
&lt;br /&gt;
===Minimise inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Almost all JavaScript code should be in separate .js files. There should be the smallest possible amount of JavaScript inline in the HTML code of pages.&lt;br /&gt;
&lt;br /&gt;
The only &amp;amp;lt;script&amp;gt; tags in the HTML should be&lt;br /&gt;
# &amp;amp;lt;script src=... tags to include the necessary .js files.&lt;br /&gt;
# Simple function calls to trigger initialisation and pass data from PHP to JavaScript. For example &amp;amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;initialise_my_widget(&#039;some&#039;, &#039;data&#039;, 123);&amp;amp;lt;/script&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Even these small amounts of JS you should not output directly. They will be generated automatically by calls to the $PAGE-&amp;gt;requries-&amp;gt;js_init_call() API. See below for details.&lt;br /&gt;
&lt;br /&gt;
You should not use old-fashioned onXXX=&amp;quot;event_handler&amp;quot; attributes in the HTML. Use Modern DOM events. The YUI events library makes this easy.&lt;br /&gt;
&lt;br /&gt;
=== JavaScript libraries ===&lt;br /&gt;
&lt;br /&gt;
* The official JavaScript library for Moodle is [[Development:YUI|YUI]]. That may not be your favourite, but it&#039;s the one that was chosen after careful research, so live with it.&lt;br /&gt;
&lt;br /&gt;
* Moodle also has its own JavaScript library code, packaged into in various JavaScript modules.&lt;br /&gt;
&lt;br /&gt;
* Moodle uses the &#039;&#039;&#039;TinyMCE&#039;&#039;&#039; HTML editor.&lt;br /&gt;
&lt;br /&gt;
===When to include the JavaScript===&lt;br /&gt;
&lt;br /&gt;
As per [http://developer.yahoo.com/performance/rules.html Yahoo&#039;s best practice guidelines], load and execute the JavaScript as late as possible, ideally the script tags should be the last thing before the &amp;amp;lt;/body&amp;gt; close tag. (This is the default behaviour with Moodle&#039;s JavaScript handling functions like $PAGE-&amp;gt;requries-&amp;gt;js_init_call().)&lt;br /&gt;
&lt;br /&gt;
Since everything should work without JavaScript, load and initialising your scripts only after everything else on the page has loaded should not be a problem and will increase the perceived page-load performance for users.&lt;br /&gt;
&lt;br /&gt;
===Minimise the number of .js files===&lt;br /&gt;
&lt;br /&gt;
Try not to use too many different .js files. Each separate file that the browser has to load incurs an overhead.&lt;br /&gt;
&lt;br /&gt;
On the other hand, organise the JavaScript logically to ease maintenance, and don&#039;t include large amounts of irrelevant JavaScript code. Code that is loaded but never used is a waste of time.&lt;br /&gt;
&lt;br /&gt;
So, if you are writing a new module that needs its own JavaScript, try starting with a single file mod/mymod/module.js. If you find that you are writing a lot of JavaScript that is only needed when the teacher edits your module, but is not needed by students, then consider splitting that code into a separate file like mod/mymod/edit.js, and only including it where needed.&lt;br /&gt;
&lt;br /&gt;
==How to achive these general principles in Moodle==&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how you can achieve the above goals.&lt;br /&gt;
&lt;br /&gt;
===Getting Moodle to load your JavaScript files===&lt;br /&gt;
&lt;br /&gt;
Everything required by the current page is tracked by the $PAGE-&amp;gt;requires object, which is an instance of the [http://phpdocs.moodle.org/HEAD/moodlecore/page_requirements_manager.html page_requirements_manager] class defined in lib/outputrequirementslib.php.&lt;br /&gt;
&lt;br /&gt;
The most important method in this class is the -&amp;gt;js_init_call(...) method. You use it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt; &lt;br /&gt;
$PAGE-&amp;gt;requires-&amp;gt;js_init_call(&#039;M.mod_mymod.init_something&#039;, array(&#039;some&#039;, &#039;data&#039;, &#039;from&#039;, &#039;PHP&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that this will implicitly load the JavaScript code in mod/mymod/module.js, and then call the M.mod_mymod.init_something function passing four string arguments &#039;some&#039;, &#039;data&#039;, &#039;from&#039;, &#039;PHP&#039;. You can pass any PHP type as an argument. The PHP values are encoded with json_encode before being passed to JavaScript, so numbers, strings, arrays and objects all work.&lt;br /&gt;
&lt;br /&gt;
Sometimes, the code in the JavaScript module mod/mymod/module.js may require some other JavaScript libraries to be loaded, or it may require some language strings. In that case you need to use the full form of js_init_call:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$jsmodule = array(&lt;br /&gt;
    &#039;name&#039;     =&amp;gt; &#039;mod_mymod&#039;,&lt;br /&gt;
    &#039;fullpath&#039; =&amp;gt; &#039;/mod/mymod/module.js&#039;,&lt;br /&gt;
    &#039;requires&#039; =&amp;gt; array(&#039;base&#039;, &#039;io&#039;, &#039;node&#039;, &#039;json&#039;),&lt;br /&gt;
    &#039;strings&#039; =&amp;gt; array(&lt;br /&gt;
        array(&#039;something&#039;, &#039;mymod&#039;),&lt;br /&gt;
        array(&#039;confirmdelete&#039;, &#039;mymod&#039;),&lt;br /&gt;
        array(&#039;yes&#039;, &#039;moodle&#039;),&lt;br /&gt;
        array(&#039;no&#039;, &#039;moodle&#039;)&lt;br /&gt;
    )&lt;br /&gt;
);&lt;br /&gt;
$PAGE-&amp;gt;requires-&amp;gt;js_init_call(&#039;M.mod_mymod.init_something&#039;, array(&#039;some&#039;, &#039;data&#039;, &#039;from&#039;, &#039;PHP&#039;), false, $jsmodule);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
(Naturally, it would be a good idea to put the definition of the $jsmodule array somewhere central like in the locallib.php file.)&lt;br /&gt;
&lt;br /&gt;
The third (boolean) parameter is defined as &amp;quot;Wait for DOM Ready&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The libraries in the &#039;requires&#039; sub-array are YUI3 (or YUI2) libraries.&lt;br /&gt;
&lt;br /&gt;
The strings are Moodle language strings. In order for Moodle to have correctly determined the user&#039;s language, you should only call js_init_call after the call to require_login, which sets the current course, and ensures the user is logged in.&lt;br /&gt;
Strings that are passed to Javascript in this way are then available from Javascript using M.util.get_string(), which works just like the PHP function.&lt;br /&gt;
&lt;br /&gt;
$PAGE-&amp;gt;requires keeps track of which files have been included. For example if two other modules both require the YUI base module, then it is only included once.&lt;br /&gt;
&lt;br /&gt;
===JavaScript coding style===&lt;br /&gt;
&lt;br /&gt;
Moodle JavaScript code should should follow the same [[Development:Coding_style|coding style as Moodle PHP code]], allowing for the differences between PHP and JavaScript.&lt;br /&gt;
&lt;br /&gt;
For example, all the rules on &#039;&#039;function_names&#039;&#039;, &#039;&#039;class_names&#039;&#039; and &#039;&#039;variablenames&#039;&#039; apply. You should document your code with [http://jsdoc.sourceforge.net/ JSDoc] comments. Layout your JavaScript expressions and statements like the equivalent PHP ones.&lt;br /&gt;
&lt;br /&gt;
Normally, your .js files should simply define things like functions, classes and variables. When the file is loaded, no JavaScript code should actually be executed that has any effect unless it is the sort of code that can safely be executed once per HTML page. This is so that it plays nicely with the require_once-like behaviour of $PAGE-&amp;gt;requires-&amp;gt;js.&lt;br /&gt;
&lt;br /&gt;
Do not pollute the global JavaScript name-space. Try to package your JavaScript into objects, and put all objects inside the global M object, like the M.mod_mymod example above. &lt;br /&gt;
&lt;br /&gt;
===Different content when JavaScript is on or off===&lt;br /&gt;
&lt;br /&gt;
Remember the overriding principals that everything should work with JavaScript off, and we should adopt a [[Progressive enhancement]] approach. However, there are valid reasons why sometimes you need different content with JavaScript is on or off. We can break it down into three cases:&lt;br /&gt;
&lt;br /&gt;
====Content that should only be visible with JavaScript off====&lt;br /&gt;
&lt;br /&gt;
An example of this is the automatic search when you are looking for a user to assign a role to. With JavaScript on, the search automatically starts after a delay. With JavaScript off, we want an explicit Search button visible.&lt;br /&gt;
&lt;br /&gt;
To handle this case, Moodle automatically add a class &#039;jsenabled&#039; to the body tag using JavaScript. So you just need to add a rule like&lt;br /&gt;
&amp;lt;code css&amp;gt;&lt;br /&gt;
body.jsenebled .mywidget .submitbutton {&lt;br /&gt;
    display: none;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
to the stylesheet, and the button will be invisible if JavaScript is enabled.&lt;br /&gt;
&lt;br /&gt;
An alternative strategy is to remove the particular bits of HTML from the page using DOM methods. However, if your JavaScript is only loaded at the end of the page, it may take some time for the extra content to disappear, which leads to a disconcerting flicker in the page.&lt;br /&gt;
&lt;br /&gt;
Yet another approach is the old-fashioned &amp;lt;noscript&amp;gt; tag.&lt;br /&gt;
&lt;br /&gt;
====Content that needs to be visible right away when JavaScript is on====&lt;br /&gt;
&lt;br /&gt;
An example is the &amp;lt;nowiki&amp;gt;[+] or [-]&amp;lt;/nowiki&amp;gt; icon that can be used to expand/collapse each block if JavaScript is on.&lt;br /&gt;
&lt;br /&gt;
We can divide this into two subcases:&lt;br /&gt;
&lt;br /&gt;
=====Content generated by PHP code=====&lt;br /&gt;
&lt;br /&gt;
Where the HTML for the JavaScript only widget is generated by PHP, we can make it invisible when JavaScript is off using just CSS:&lt;br /&gt;
&amp;lt;code css&amp;gt;&lt;br /&gt;
.mywidget {&lt;br /&gt;
    display: none;&lt;br /&gt;
}&lt;br /&gt;
body.jsenabled .mywidget {&lt;br /&gt;
    display: block;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
However, it could be argued that this approach is not really progressive enhancement.&lt;br /&gt;
&lt;br /&gt;
=====Content generated by JavaScript code=====&lt;br /&gt;
&lt;br /&gt;
This is more in keeping with progressive enhancement, and this is the way that the expand/collapse block icon is handled.&lt;br /&gt;
&lt;br /&gt;
We build the icon using DOM methods. The only problem is that as the JavaScript is loaded in the footer, there is a small delay before the icons appear. Since when the icons appear, they do not cause other content on the page to move around, that is OK. Also, this delayed appearance is becoming more common on the web. For example, on http://twitter.com/, some things only appear a moment after the main part of the page has finished loading.&lt;br /&gt;
&lt;br /&gt;
However, it the delayed appearance is really a problem, then the only solution is to embed the JavaScript that generates the extra content in the middle of the HTML, using the js_writer class.&lt;br /&gt;
&lt;br /&gt;
====Content that only appears when the user does something, when JavaScript is on====&lt;br /&gt;
&lt;br /&gt;
An example of this is something like file picker dialog that appears when you add an image to some content in the HTML editor, or the one that pops up when you click &#039;Add new question&#039; in the quiz editing interface.&lt;br /&gt;
&lt;br /&gt;
We have the same two sub-cases:&lt;br /&gt;
&lt;br /&gt;
=====Content generated by PHP code=====&lt;br /&gt;
&lt;br /&gt;
In this case, you need to make sure the content is always covered by a &#039;&#039;display: none;&#039;&#039; rule in the CSS, but then when the user takes an action like clicking a button to reveal the extra content, you need to override that class name some how, perhaps by adding or removing a className using JavaScript.&lt;br /&gt;
&lt;br /&gt;
=====Content generated by JavaScript code=====&lt;br /&gt;
&lt;br /&gt;
In this case, there is no problem. When the use triggers the extra content to appear, it is constructed using DOM methods. There may be a tiny delay, but the chances are that it will hardly be noticeable to the human eye.&lt;br /&gt;
&lt;br /&gt;
If the content generation may be slow (perhaps because it is waiting for an Ajax request) then you should display a progress icon. See, for example, the loading of the tooltip for help icons.&lt;br /&gt;
&lt;br /&gt;
===Don&#039;t break XHTML strict!===&lt;br /&gt;
&lt;br /&gt;
Remember that all Moodle output must be [[Development:XHTML|XHTML strict]], and that means that the HTML output must be well-formed XML. Inline JavaScript is a great way to break that. (JavaScript uses the &amp;lt; and &amp;amp; symbols that must be escaped in XML.) Therefore any JavaScript inline in the HTML should be escaped in a CDATA section:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code xml&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
//&amp;lt;![CDATA[&lt;br /&gt;
&lt;br /&gt;
   // Your JavaScript code goes here.&lt;br /&gt;
&lt;br /&gt;
//]]&amp;gt;&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, if you are following the above guidelines and putting most of your JavaScript in separate .js files, and using $PAGE-&amp;gt;requires-&amp;gt;js_init_call, then this is taken care of for you automatically.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
JavaScript support varies a lot between browsers. JavaScript needs to be tested in IE, Firefox and Safari. Ideally, Moodle will support [http://developer.yahoo.com/yui/articles/gbs/ all the browsers that YUI does].&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:Coding|The rest of Moodle coding guidelines]]&lt;br /&gt;
* [http://developer.yahoo.com/yui/ YUI documentation]&lt;br /&gt;
* [[Javascript FAQ]]&lt;br /&gt;
* [[Javascript and YUI 3 FAQ]]&lt;br /&gt;
* [[Development:Unobtrusive Javascript]]&lt;br /&gt;
* [[Development:JavaScript functions]]&lt;br /&gt;
* [http://developer.yahoo.com/performance/rules.html Yahoo&#039;s Best Practices for Speeding Up Your Web Site]&lt;br /&gt;
&lt;br /&gt;
[[Category:Coding guidelines|JavaScript guidelines]]&lt;br /&gt;
[[Category:Javascript|JavaScript guidelines]]&lt;br /&gt;
[[Category:AJAX|JavaScript guidelines]]&lt;br /&gt;
&lt;br /&gt;
[[ja:開発:Javaスクリプトガイドライン]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:JavaScript_guidelines&amp;diff=81141</id>
		<title>Development:JavaScript guidelines</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:JavaScript_guidelines&amp;diff=81141"/>
		<updated>2011-02-08T13:52:29Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* How to achive these general principles in Moodle */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
These guidelines can only be applied fully from Moodle 2.0 onwards, because they rely on our new API to facilitate use of JavaScript.&lt;br /&gt;
&lt;br /&gt;
When writing JavaScript for earlier versions of Moodle, please try to follow these guidelines in spirit and use the &#039;&#039;&#039;require_js&#039;&#039;&#039; function in place of $PAGE-&amp;gt;requires-&amp;gt;js_module/yui2_lib.&lt;br /&gt;
&lt;br /&gt;
==General principles==&lt;br /&gt;
&lt;br /&gt;
===Moodle should be usable without JavaScript===&lt;br /&gt;
&lt;br /&gt;
Everything in Moodle should work with JavaScript turned off. This is important for accessibility, and in line with the principles of [[Development:Unobtrusive_Javascript|unobtrusive JavaScript]] and [[Development:Progressive_enhancement|progressive enhancement]].&lt;br /&gt;
&lt;br /&gt;
===Minimise inline JavaScript===&lt;br /&gt;
&lt;br /&gt;
Almost all JavaScript code should be in separate .js files. There should be the smallest possible amount of JavaScript inline in the HTML code of pages.&lt;br /&gt;
&lt;br /&gt;
The only &amp;amp;lt;script&amp;gt; tags in the HTML should be&lt;br /&gt;
# &amp;amp;lt;script src=... tags to include the necessary .js files.&lt;br /&gt;
# Simple function calls to trigger initialisation and pass data from PHP to JavaScript. For example &amp;amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;initialise_my_widget(&#039;some&#039;, &#039;data&#039;, 123);&amp;amp;lt;/script&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Even these small amounts of JS you should not output directly. They will be generated automatically by calls to the $PAGE-&amp;gt;requries-&amp;gt;js_init_call() API. See below for details.&lt;br /&gt;
&lt;br /&gt;
You should not use old-fashioned onXXX=&amp;quot;event_handler&amp;quot; attributes in the HTML. Use Modern DOM events. The YUI events library makes this easy.&lt;br /&gt;
&lt;br /&gt;
=== JavaScript libraries ===&lt;br /&gt;
&lt;br /&gt;
* The official JavaScript library for Moodle is [[Development:YUI|YUI]]. That may not be your favourite, but it&#039;s the one that was chosen after careful research, so live with it.&lt;br /&gt;
&lt;br /&gt;
* Moodle also has its own JavaScript library code, packaged into in various JavaScript modules.&lt;br /&gt;
&lt;br /&gt;
* Moodle uses the &#039;&#039;&#039;TinyMCE&#039;&#039;&#039; HTML editor.&lt;br /&gt;
&lt;br /&gt;
===When to include the JavaScript===&lt;br /&gt;
&lt;br /&gt;
As per [http://developer.yahoo.com/performance/rules.html Yahoo&#039;s best practice guidelines], load and execute the JavaScript as late as possible, ideally the script tags should be the last thing before the &amp;amp;lt;/body&amp;gt; close tag. (This is the default behaviour with Moodle&#039;s JavaScript handling functions like $PAGE-&amp;gt;requries-&amp;gt;js_init_call().)&lt;br /&gt;
&lt;br /&gt;
Since everything should work without JavaScript, load and initialising your scripts only after everything else on the page has loaded should not be a problem and will increase the perceived page-load performance for users.&lt;br /&gt;
&lt;br /&gt;
===Minimise the number of .js files===&lt;br /&gt;
&lt;br /&gt;
Try not to use too many different .js files. Each separate file that the browser has to load incurs an overhead.&lt;br /&gt;
&lt;br /&gt;
On the other hand, organise the JavaScript logically to ease maintenance, and don&#039;t include large amounts of irrelevant JavaScript code. Code that is loaded but never used is a waste of time.&lt;br /&gt;
&lt;br /&gt;
So, if you are writing a new module that needs its own JavaScript, try starting with a single file mod/mymod/module.js. If you find that you are writing a lot of JavaScript that is only needed when the teacher edits your module, but is not needed by students, then consider splitting that code into a separate file like mod/mymod/edit.js, and only including it where needed.&lt;br /&gt;
&lt;br /&gt;
==How to achive these general principles in Moodle==&lt;br /&gt;
&lt;br /&gt;
The rest of this page explains how you can achieve the above goals.&lt;br /&gt;
&lt;br /&gt;
===Getting Moodle to load your JavaScript files===&lt;br /&gt;
&lt;br /&gt;
Everything required by the current page is tracked by the $PAGE-&amp;gt;requires object, which is an instance of the [http://phpdocs.moodle.org/HEAD/moodlecore/page_requirements_manager.html page_requirements_manager] class defined in lib/outputrequirementslib.php.&lt;br /&gt;
&lt;br /&gt;
The most important method in this class is the -&amp;gt;js_init_call(...) method. You use it like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt; &lt;br /&gt;
$PAGE-&amp;gt;requires-&amp;gt;js_init_call(&#039;M.mod_mymod.init_something&#039;, array(&#039;some&#039;, &#039;data&#039;, &#039;from&#039;, &#039;PHP&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that this will implicitly load the JavaScript code in mod/mymod/module.js, and then call the M.mod_mymod.init_something function passing four string arguments &#039;some&#039;, &#039;data&#039;, &#039;from&#039;, &#039;PHP&#039;. You can pass any PHP type as an argument. The PHP values are encoded with json_encode before being passed to JavaScript, so numbers, strings, arrays and objects all work.&lt;br /&gt;
&lt;br /&gt;
Sometimes, the code in the JavaScript module mod/mymod/module.js may require some other JavaScript libraries to be loaded, or it may require some language strings. In that case you need to use the full form of js_init_call:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$jsmodule = array(&lt;br /&gt;
    &#039;name&#039;     =&amp;gt; &#039;mod_mymod&#039;,&lt;br /&gt;
    &#039;fullpath&#039; =&amp;gt; &#039;/mod/mymod/module.js&#039;,&lt;br /&gt;
    &#039;requires&#039; =&amp;gt; array(&#039;base&#039;, &#039;io&#039;, &#039;node&#039;, &#039;json&#039;),&lt;br /&gt;
    &#039;strings&#039; =&amp;gt; array(&lt;br /&gt;
        array(&#039;something&#039;, &#039;mymod&#039;),&lt;br /&gt;
        array(&#039;confirmdelete&#039;, &#039;mymod&#039;),&lt;br /&gt;
        array(&#039;yes&#039;, &#039;moodle&#039;),&lt;br /&gt;
        array(&#039;no&#039;, &#039;moodle&#039;)&lt;br /&gt;
    )&lt;br /&gt;
);&lt;br /&gt;
$PAGE-&amp;gt;requires-&amp;gt;js_init_call(&#039;M.mod_mymod.init_something&#039;, array(&#039;some&#039;, &#039;data&#039;, &#039;from&#039;, &#039;PHP&#039;), false, $jsmodule);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
(Naturally, it would be a good idea to put the definition of the $jsmodule array somewhere central like in the locallib.php file.)&lt;br /&gt;
&lt;br /&gt;
The third (boolean) parameter is defined as &amp;quot;Wait for DOM Ready&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The libraries in the &#039;requires&#039; sub-array are YUI3 (or YUI2) libraries.&lt;br /&gt;
&lt;br /&gt;
The strings are Moodle language strings. In order for Moodle to have correctly determined the user&#039;s language, you should only call js_init_call after the call to require_login, which sets the current course, and ensures the user is logged in.&lt;br /&gt;
Strings that are passed to Javascript in this way are then available from Javascript using M.util.get_string(), which works just like the PHP function.&lt;br /&gt;
&lt;br /&gt;
$PAGE-&amp;gt;requires keeps track of which files have been included. For example if two other modules both require the YUI base module, then it is only included once.&lt;br /&gt;
&lt;br /&gt;
===JavaScript coding style===&lt;br /&gt;
&lt;br /&gt;
Moodle JavaScript code should should follow the same [[Development:Coding_style|coding style as Moodle PHP code]], allowing for the differences between PHP and JavaScript.&lt;br /&gt;
&lt;br /&gt;
For example, all the rules on &#039;&#039;function_names&#039;&#039;, &#039;&#039;class_names&#039;&#039; and &#039;&#039;variablenames&#039;&#039; apply. You should document your code with [http://jsdoc.sourceforge.net/ JSDoc] comments. Layout your JavaScript expressions and statements like the equivalent PHP ones.&lt;br /&gt;
&lt;br /&gt;
Normally, your .js files should simply define things like functions, classes and variables. When the file is loaded, no JavaScript code should actually be executed that has any effect unless it is the sort of code that can safely be executed once per HTML page. This is so that it plays nicely with the require_once-like behaviour of $PAGE-&amp;gt;requires-&amp;gt;js.&lt;br /&gt;
&lt;br /&gt;
Do not pollute the global JavaScript name-space. Try to package your JavaScript into objects, and put all objects inside the global M object, like the M.mod_mymod example above. &lt;br /&gt;
&lt;br /&gt;
===Different content when JavaScript is on or off===&lt;br /&gt;
&lt;br /&gt;
Remember the overriding principals that everything should work with JavaScript off, and we should adopt a [[Progressive enhancement]] approach. However, there are valid reasons why sometimes you need different content with JavaScript is on or off. We can break it down into three cases:&lt;br /&gt;
&lt;br /&gt;
====Content that should only be visible with JavaScript off====&lt;br /&gt;
&lt;br /&gt;
An example of this is the automatic search when you are looking for a user to assign a role to. With JavaScript on, the search automatically starts after a delay. With JavaScript off, we want an explicit Search button visible.&lt;br /&gt;
&lt;br /&gt;
To handle this case, Moodle automatically add a class &#039;jsenabled&#039; to the body tag using JavaScript. So you just need to add a rule like&lt;br /&gt;
&amp;lt;code css&amp;gt;&lt;br /&gt;
body.jsenebled .mywidget .submitbutton {&lt;br /&gt;
    display: none;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
to the stylesheet, and the button will be invisible if JavaScript is enabled.&lt;br /&gt;
&lt;br /&gt;
An alternative strategy is to remove the particular bits of HTML from the page using DOM methods. However, if your JavaScript is only loaded at the end of the page, it may take some time for the extra content to disappear, which leads to a disconcerting flicker in the page.&lt;br /&gt;
&lt;br /&gt;
Yet another approach is the old-fashioned &amp;lt;noscript&amp;gt; tag.&lt;br /&gt;
&lt;br /&gt;
====Content that needs to be visible right away when JavaScript is on====&lt;br /&gt;
&lt;br /&gt;
An example is the &amp;lt;nowiki&amp;gt;[+] or [-]&amp;lt;/nowiki&amp;gt; icon that can be used to expand/collapse each block if JavaScript is on.&lt;br /&gt;
&lt;br /&gt;
We can divide this into two subcases:&lt;br /&gt;
&lt;br /&gt;
=====Content generated by PHP code=====&lt;br /&gt;
&lt;br /&gt;
Where the HTML for the JavaScript only widget is generated by PHP, we can make it invisible when JavaScript is off using just CSS:&lt;br /&gt;
&amp;lt;code css&amp;gt;&lt;br /&gt;
.mywidget {&lt;br /&gt;
    display: none;&lt;br /&gt;
}&lt;br /&gt;
body.jsenabled .mywidget {&lt;br /&gt;
    display: block;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
However, it could be argued that this approach is not really progressive enhancement.&lt;br /&gt;
&lt;br /&gt;
=====Content generated by JavaScript code=====&lt;br /&gt;
&lt;br /&gt;
This is more in keeping with progressive enhancement, and this is the way that the expand/collapse block icon is handled.&lt;br /&gt;
&lt;br /&gt;
We build the icon using DOM methods. The only problem is that as the JavaScript is loaded in the footer, there is a small delay before the icons appear. Since when the icons appear, they do not cause other content on the page to move around, that is OK. Also, this delayed appearance is becoming more common on the web. For example, on http://twitter.com/, some things only appear a moment after the main part of the page has finished loading.&lt;br /&gt;
&lt;br /&gt;
However, it the delayed appearance is really a problem, then the only solution is to embed the JavaScript that generates the extra content in the middle of the HTML, using the js_writer class.&lt;br /&gt;
&lt;br /&gt;
====Content that only appears when the user does something, when JavaScript is on====&lt;br /&gt;
&lt;br /&gt;
An example of this is something like file picker dialog that appears when you add an image to some content in the HTML editor, or the one that pops up when you click &#039;Add new question&#039; in the quiz editing interface.&lt;br /&gt;
&lt;br /&gt;
We have the same two sub-cases:&lt;br /&gt;
&lt;br /&gt;
=====Content generated by PHP code=====&lt;br /&gt;
&lt;br /&gt;
In this case, you need to make sure the content is always covered by a &#039;&#039;display: none;&#039;&#039; rule in the CSS, but then when the user takes an action like clicking a button to reveal the extra content, you need to override that class name some how, perhaps by adding or removing a className using JavaScript.&lt;br /&gt;
&lt;br /&gt;
=====Content generated by JavaScript code=====&lt;br /&gt;
&lt;br /&gt;
In this case, there is no problem. When the use triggers the extra content to appear, it is constructed using DOM methods. There may be a tiny delay, but the chances are that it will hardly be noticeable to the human eye.&lt;br /&gt;
&lt;br /&gt;
If the content generation may be slow (perhaps because it is waiting for an Ajax request) then you should display a progress icon. See, for example, the loading of the tooltip for help icons.&lt;br /&gt;
&lt;br /&gt;
===Don&#039;t break XHTML strict!===&lt;br /&gt;
&lt;br /&gt;
Remember that all Moodle output must be [[Development:XHTML|XHTML strict]], and that means that the HTML output must be well-formed XML. Inline JavaScript is a great way to break that. (JavaScript uses the &amp;lt; and &amp;amp; symbols that must be escaped in XML.) Therefore any JavaScript inline in the HTML should be escaped in a CDATA section:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code xml&amp;gt;&lt;br /&gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;
//&amp;lt;![CDATA[&lt;br /&gt;
&lt;br /&gt;
   // Your JavaScript code goes here.&lt;br /&gt;
&lt;br /&gt;
//]]&amp;gt;&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, if you are following the above guidelines and putting most of your JavaScript in separate .js files, and using $PAGE-&amp;gt;requires-&amp;gt;js_init_call, then this is taken care of for you automatically.&lt;br /&gt;
&lt;br /&gt;
==Testing==&lt;br /&gt;
&lt;br /&gt;
JavaScript support varies a lot between browsers. JavaScript needs to be tested in IE, Firefox and Safari. Ideally, Moodle will support [http://developer.yahoo.com/yui/articles/gbs/ all the browsers that YUI does].&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [[Development:Coding|The rest of Moodle coding guidelines]]&lt;br /&gt;
* [http://developer.yahoo.com/yui/ YUI documentation]&lt;br /&gt;
* [[Javascript FAQ]]&lt;br /&gt;
* [[Development:Unobtrusive Javascript]]&lt;br /&gt;
* [[Development:JavaScript functions]]&lt;br /&gt;
* [http://developer.yahoo.com/performance/rules.html Yahoo&#039;s Best Practices for Speeding Up Your Web Site]&lt;br /&gt;
&lt;br /&gt;
[[Category:Coding guidelines|JavaScript guidelines]]&lt;br /&gt;
[[Category:Javascript|JavaScript guidelines]]&lt;br /&gt;
[[Category:AJAX|JavaScript guidelines]]&lt;br /&gt;
&lt;br /&gt;
[[ja:開発:Javaスクリプトガイドライン]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Message_My_Teacher_Block&amp;diff=80612</id>
		<title>Message My Teacher Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Message_My_Teacher_Block&amp;diff=80612"/>
		<updated>2011-01-18T14:54:36Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: New page: Message My Teacher is a very simple block. It will display a list users who are teachers for the current course with links to send them a message.  == Configuration == The block requires t...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Message My Teacher is a very simple block. It will display a list users who are teachers for the current course with links to send them a message.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
The block requires that you select the roles you wish to consider &amp;quot;teachers&amp;quot; (those who will appear in the block).  In Site Administration/Plugins/Blocks/Message My Teacher you can select as many roles as necessary by checking the appropriate boxes.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
Anyone visiting a page with the block on will see a list of all users with the selected roles. Clicking the user&#039;s name will take them to a screen allowing them to compose a message to that user. &#039;&#039;&#039;Note:&#039;&#039;&#039; users will never see their own name on this list, as they will never need to message themselves. If they are assigned the appropriate role, they will still appear to other users. &lt;br /&gt;
&lt;br /&gt;
[[Category:Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Metacourse_Link_Block&amp;diff=80611</id>
		<title>Metacourse Link Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Metacourse_Link_Block&amp;diff=80611"/>
		<updated>2011-01-18T14:49:05Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: New page: This block allows Metacourse/Child course links to be created/kept up to date via CSV files. It is very similar in both appearance and programming to the Tutor Link Block.  It can be o...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This block allows Metacourse/Child course links to be created/kept up to date via CSV files. It is very similar in both appearance and programming to the [[Tutor Link Block]].&lt;br /&gt;
&lt;br /&gt;
It can be operated in two modes:&lt;br /&gt;
&lt;br /&gt;
Manual Upload - any user with the block/metalink:use capability (by default, only admins) can upload a file to process on demand.&lt;br /&gt;
&lt;br /&gt;
Automatic - a file location is configured, then the block automatically checks this location. If a file is found, it is processed and results emailed to the administrator.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
The block has several configuration options, found in Site Administration/Plugins/Blocks/Upload Tutor Relationships.&lt;br /&gt;
*&#039;&#039;Location of File for Automatic Processing&#039;&#039; is the location of the file on the server&#039;s local file system to be processed by the block&#039;s cron job, allowing periodic updates of role assignments.  Leaving this blank will disable the cron job.&lt;br /&gt;
*&#039;&#039;Keep processed files&#039;&#039; allows files processed by cron jobs to be kept for future reference.&lt;br /&gt;
*&#039;&#039;Processed file location&#039;&#039; is the folder that processed files will be placed in, if &#039;&#039;Keep processed files&#039;&#039; is ticked.&lt;br /&gt;
*&#039;&#039;Days to keep processed files for&#039;&#039; is self-explanatory. After this many days, processed files will be deleted.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
=== Correct File Format ===&lt;br /&gt;
The files to be processed should be in CSV format (hopefully no surprises there). &lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
They may consist of any number of rows, each with three fields: tutor idnumber,tutee idnumber, action; it is important to note that the idnumbers are expected to be populated from an external database, they are not the id field in the user table. Action can be add or del, with add creating relationships and del deleting relationships. None of the fields should be delimited.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
As of Moodle 2.0, the order of the fields changed slightly to make them more consistent with the Flatfile Enrolements plugin.&lt;br /&gt;
The format for each row is now: action, parent course idnumber, child course idnumber. For example, a file with this contents:&lt;br /&gt;
 add, 1234, 4321&lt;br /&gt;
 add, 1234, 4322&lt;br /&gt;
 del, 2232, 3223&lt;br /&gt;
Will assign the courses with idnumbers 4321 and 4321 as children of the course with idnumber 1234, then remove the course with idnumber 3223 from the course with idnumber 2232.&lt;br /&gt;
Note than unlike 1.9, each row &#039;&#039;&#039;must&#039;&#039;&#039; contain three columns.&lt;br /&gt;
&lt;br /&gt;
Trying to add relationships that already exist in Moodle or remove those that dont will not cause problems, as this block will skip over those records.&lt;br /&gt;
&lt;br /&gt;
=== Manual upload ===&lt;br /&gt;
After the CSV file is created, navigate to the page containing the block, and upload the file. It will be processed and a report will appear showing you the operations that were successful, along with any errors.&lt;br /&gt;
&lt;br /&gt;
=== Automatic processing ===&lt;br /&gt;
A file placed at the path specified in &#039;&#039;Location of file for automatic processing&#039;&#039; will be processed automatically when the block&#039;s cron job runs.  A report will then be emailed to the Moodle Administrator.&lt;br /&gt;
&lt;br /&gt;
[[Category:Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Tutor_Link_Block&amp;diff=80610</id>
		<title>Tutor Link Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Tutor_Link_Block&amp;diff=80610"/>
		<updated>2011-01-18T14:44:54Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This block allows user relationships (that is one user assigned a role in another user&#039;s context) to be created/kept up to date via CSV files. It was written for personal tutors, but would work equally well for parents.&lt;br /&gt;
&lt;br /&gt;
It can be operated in two modes:&lt;br /&gt;
&lt;br /&gt;
Manual Upload - any user with the block/tutorlink:use capability (by default, only admins) can upload a file to process on demand.&lt;br /&gt;
&lt;br /&gt;
Automatic - a file location is configured, then the block automatically checks this location. If a file is found, it is processed and results emailed to the administrator.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
The block has several configuration options, found in Site Administration/Plugins/Blocks/Upload Tutor Relationships.&lt;br /&gt;
*&#039;&#039;Tutor Role&#039;&#039; is the role that will be assigned by the block. As of 2.0, a role must be allowed to be assigned at the User context level before it can be selected here. This is configured on the role&#039;s &#039;&#039;Define Role&#039;&#039; page.&lt;br /&gt;
*&#039;&#039;Location of File for Automatic Processing&#039;&#039; is the location of the file on the server&#039;s local file system to be processed by the block&#039;s cron job, allowing periodic updates of role assignments.  Leaving this blank will disable the cron job.&lt;br /&gt;
*&#039;&#039;Keep processed files&#039;&#039; allows files processed by cron jobs to be kept for future reference.&lt;br /&gt;
*&#039;&#039;Processed file location&#039;&#039; is the folder that processed files will be placed in, if &#039;&#039;Keep processed files&#039;&#039; is ticked.&lt;br /&gt;
*&#039;&#039;Days to keep processed files for&#039;&#039; is self-explanatory. After this many days, processed files will be deleted.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
=== Correct File Format ===&lt;br /&gt;
The files to be processed should be in CSV format (hopefully no surprises there). &lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
They may consist of any number of rows, each with three fields: tutor idnumber,tutee idnumber, action; it is important to note that the idnumbers are expected to be populated from an external database, they are not the id field in the user table. Action can be add or del, with add creating relationships and del deleting relationships. None of the fields should be delimited.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
As of Moodle 2.0, the order of the fields changed slightly to make them more consistent with the Flatfile Enrolements plugin.&lt;br /&gt;
The format for each row is now: action, tutor idnumber, tutee idnumber. For example, a file with this contents:&lt;br /&gt;
 add, 1234, 4321&lt;br /&gt;
 add, 1234, 4322&lt;br /&gt;
 del, 2232, 3223&lt;br /&gt;
Will assign the user with the idnumber 1234 to users with idnumbers 4321 and 4321, then remove the user with idnumber 2232 from the user 3223.&lt;br /&gt;
&lt;br /&gt;
Trying to add relationships that already exist in Moodle or remove those that dont will not cause problems, as this block will skip over those records.&lt;br /&gt;
&lt;br /&gt;
=== Manual upload ===&lt;br /&gt;
After the CSV file is created, navigate to the page containing the block, and upload the file. It will be processed and a report will appear showing you the operations that were successful, along with any errors.&lt;br /&gt;
&lt;br /&gt;
=== Automatic processing ===&lt;br /&gt;
A file placed at the path specified in &#039;&#039;Location of file for automatic processing&#039;&#039; will be processed automatically when the block&#039;s cron job runs.  A report will then be emailed to the Moodle Administrator.&lt;br /&gt;
&lt;br /&gt;
[[Category:Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=CSV_user_relationships_block&amp;diff=80609</id>
		<title>CSV user relationships block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=CSV_user_relationships_block&amp;diff=80609"/>
		<updated>2011-01-18T14:42:50Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Redirecting to Tutor Link Block&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Tutor Link Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=CSV_user_relationships_block&amp;diff=80608</id>
		<title>CSV user relationships block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=CSV_user_relationships_block&amp;diff=80608"/>
		<updated>2011-01-18T14:42:26Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Redirecting to Quick Find List Block&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Quick Find List Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Tutor_Link_Block&amp;diff=80607</id>
		<title>Tutor Link Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Tutor_Link_Block&amp;diff=80607"/>
		<updated>2011-01-18T14:40:21Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Copied from old CSV_user_relationships_block page and updated to include Moodle 2 specifics&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This block allows user relationships (that is one user assigned a role in another user&#039;s context) to be created/kept up to date via CSV files. It was written for personal tutors, but would work equally well for parents.&lt;br /&gt;
&lt;br /&gt;
It can be operated in two modes:&lt;br /&gt;
&lt;br /&gt;
Manual Upload - any user with the block/tutorlink:use capability (by default, only admins) can upload a file to process on demand.&lt;br /&gt;
&lt;br /&gt;
Automatic - a file location is configured, then the block automatically checks this location. If a file is found, it is processed and results emailed to the administrator.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
The block has several configuration options, found in Site Administration/Plugins/Blocks/Upload Tutor Relationships.&lt;br /&gt;
*&#039;&#039;Tutor Role&#039;&#039; is the role that will be assigned by the block. As of 2.0, a role must be allowed to be assigned at the User context level. This is configured on the role&#039;s &#039;&#039;Define Role&#039;&#039; page.&lt;br /&gt;
*&#039;&#039;Location of File for Automatic Processing&#039;&#039; is the location of the file on the server&#039;s local file system to be processed by the block&#039;s cron job, allowing periodic updates of role assignments.  Leaving this blank will disable the cron job.&lt;br /&gt;
*&#039;&#039;Keep processed files&#039;&#039; allows files processed by cron jobs to be kept for future reference.&lt;br /&gt;
*&#039;&#039;Processed file location&#039;&#039; is the folder that processed files will be placed in, if &#039;&#039;Keep processed files&#039;&#039; is ticked.&lt;br /&gt;
*&#039;&#039;Days to keep processed files for&#039;&#039; is self-explanatory. After this many days, processed files will be deleted.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
=== Correct File Format ===&lt;br /&gt;
The files to be processed should be in CSV format (hopefully no surprises there). &lt;br /&gt;
&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
They may consist of any number of rows, each with three fields: tutor idnumber,tutee idnumber, action; it is important to note that the idnumbers are expected to be populated from an external database, they are not the id field in the user table. Action can be add or del, with add creating relationships and del deleting relationships. None of the fields should be delimited.&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
As of Moodle 2.0, the order of the fields changed slightly to make them more consistent with the Flatfile Enrolements plugin.&lt;br /&gt;
The format for each row is now: action, tutor idnumber, tutee idnumber. For example, a file with this contents:&lt;br /&gt;
 add, 1234, 4321&lt;br /&gt;
 add, 1234, 4322&lt;br /&gt;
 del, 2232, 3223&lt;br /&gt;
Will assign the user with the idnumber 1234 to users with idnumbers 4321 and 4321, then remove the user with idnumber 2232 from the user 3223.&lt;br /&gt;
&lt;br /&gt;
Trying to add relationships that already exist in Moodle or remove those that dont will not cause problems, as this block will skip over those records.&lt;br /&gt;
&lt;br /&gt;
=== Manual upload ===&lt;br /&gt;
After the CSV file is created, navigate to the page containing the block, and upload the file. It will be processed and a report will appear showing you the operations that were successful, along with any errors.&lt;br /&gt;
&lt;br /&gt;
=== Automatic processing ===&lt;br /&gt;
A file placed at the path specified in &#039;&#039;Location of file for automatic processing&#039;&#039; will be processed automatically when the block&#039;s cron job runs.  A report will then be emailed to the Moodle Administrator.&lt;br /&gt;
&lt;br /&gt;
[[Category:Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Accessibility_Block&amp;diff=80606</id>
		<title>Accessibility Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Accessibility_Block&amp;diff=80606"/>
		<updated>2011-01-18T14:15:21Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Accessibility Block allows users to customise Moodle pages to meet their accessibility requirements.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
In Moodle 1.9, You will need to make a slight modification to any themes that your site uses to enable the block&#039;s customisations to be carried between pages.  Simply open the &amp;lt;tt&amp;gt;header.html&amp;lt;/tt&amp;gt; file of each theme, and add the following line before the &amp;lt;tt&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;/tt&amp;gt; tag:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;!-- patch to allow custom font sizes from block_accessibility --&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;link title=&amp;quot;access_stylesheet&amp;quot; &lt;br /&gt;
  rel=&amp;quot;stylesheet&amp;quot; &lt;br /&gt;
  href=&amp;quot;&amp;lt;?php if($CFG-&amp;gt;wwwroot != $CFG-&amp;gt;httpswwwroot) {echo $CFG-&amp;gt;httpswwwroot;} else {echo $CFG-&amp;gt;wwwroot;} ?&amp;gt;&lt;br /&gt;
  /blocks/accessibility/userstyles.php&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
As of Moodle 2, the block requires no additional configuration to get per-user style modifications working. Since 2.0 the block includes [http://access.ecs.soton.ac.uk/ToolBar/ ATbar], which provides Text-To-Speech functionality (TTS). To get TTS working, you&#039;ll need to follow these instructions (currently only supported on Linux servers).&lt;br /&gt;
#Install the Accessibility block as normal&lt;br /&gt;
#Install Festival, the Text-To-Speech engine, on your server. This should install text2wave in /usr/bin. If not, you&#039;ll need to symlink it there.&lt;br /&gt;
#Install LAME, the MP3 utilities, on your server.&lt;br /&gt;
#Go to the Moodle root directory (at command line or in a file manager)&lt;br /&gt;
#From here, find blocks/accessibility/toolbar/server/TTS/SB_generateAudio.sh and make it executable. To do this from the terminal, run: &amp;lt;pre&amp;gt;chmod +x blocks/accessibility/toolbar/server/TTS/SB_generateAudio.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
#Edit SB_generateAudio.sh to set the tmpdir variable at the top to a suitable temporary directory, and dirroot to the value of $CFG-&amp;gt;dirroot in your Moodle config.php&lt;br /&gt;
#Change the ownership of blocks/accessibility/toolbar/server/TTS/cache to make it writable by the user the web server runs as. To do this on Ubuntu, run these commands: &amp;lt;pre&amp;gt;chown -R user:www-data blocks/accessibility/toolbar/server/TTS/cache&amp;lt;/pre&amp;gt;  &amp;lt;pre&amp;gt;chmod -R 775 blocks/accessibility/toolbar/server/TTS/cache&amp;lt;/pre&amp;gt;&lt;br /&gt;
#Load a Moodle page containing the block, click &amp;quot;Launch ATbar&amp;quot;, select some text, and click the Text-To-Speech button (speaker icon).&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
The block&#039;s functionality is split into 2 areas: Native functions, and those functions provided bt ATbar.&lt;br /&gt;
=== Native Functions ===&lt;br /&gt;
There are 8 buttons on the block itself. The 3 buttons on the top row displaying an &#039;&#039;A&#039;&#039; control text size:&lt;br /&gt;
*Clicking [[Image:Accessibility_A-.png]] will decrease the text size.&lt;br /&gt;
*Clicking [[Image:Accessibility_A+.png]] will increase the text size.&lt;br /&gt;
*Clicking [[Image:Accessibility_A.png]] will reset the text size. If you had a saved setting for the text size, this will be cleared.&lt;br /&gt;
&lt;br /&gt;
The final button on the top row saves styles changed by the block. Once you have altered the text size or colour scheme, the button will become active, shown by the blue arrow. When it&#039;s active, click [[Image:Accessibility_save.png]] to save settings. Once saved, they will persist between pages even when you log out.&lt;br /&gt;
&lt;br /&gt;
The bottom row contains 4 buttons, each displaying a different colour scheme. Clicking any of these buttons [[Image:Accessibility_colours.png]] will apply that colour scheme to the page. Clicking the button on the far left will reset the scheme to default and clear any saved colour settings.&lt;br /&gt;
&lt;br /&gt;
=== ATbar ===&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
At the bottom of the block, you&#039;ll see a button labelled &#039;&#039;Launch ATbar&#039;&#039; and a checkbox labelled &#039;&#039;(always?)&#039;&#039;&amp;lt;br /&amp;gt;&lt;br /&gt;
[[Image:Accessibility_atbar.png]]&amp;lt;br /&amp;gt;&lt;br /&gt;
Clicking the button will launch ATbar and hide the native controls. ATbar has several advanced Accessibility functions on top of the ability to change page styles, including Text-To-Speech and Dictionary lookup. Note that if you change styles with ATbar, they will &#039;&#039;&#039;not&#039;&#039;&#039; persist between pages as they do with the native functions, nor are you currently able to save them.&lt;br /&gt;
Ticking the checkbox will cause ATbar to be automatically loaded each time you visit a page containing the Accessibility block.&lt;br /&gt;
You can find out more about ATbar&#039;s functions by clicking the [[Image:Accessibility_help.png]] icon on the right of the bar itself.&lt;br /&gt;
&lt;br /&gt;
[[Category:Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Accessibility_Block&amp;diff=80605</id>
		<title>Accessibility Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Accessibility_Block&amp;diff=80605"/>
		<updated>2011-01-18T14:13:51Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: New page: The Accessibility Block allows users to customise Moodle pages to meet their accessibility requirements.  == Configuration == {{Moodle 1.9}} In Moodle 1.9, You will need to make a slight m...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Accessibility Block allows users to customise Moodle pages to meet their accessibility requirements.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
In Moodle 1.9, You will need to make a slight modification to any themes that your site uses to enable the block&#039;s customisations to be carried between pages.  Simply open the &amp;lt;tt&amp;gt;header.html&amp;lt;/tt&amp;gt; file of each theme, and add the following line before the &amp;lt;tt&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;/tt&amp;gt; tag:&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;&amp;lt;!-- patch to allow custom font sizes from block_accessibility --&amp;gt;&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
 &amp;lt;link title=&amp;quot;access_stylesheet&amp;quot; &lt;br /&gt;
  rel=&amp;quot;stylesheet&amp;quot; &lt;br /&gt;
  href=&amp;quot;&amp;lt;?php if($CFG-&amp;gt;wwwroot != $CFG-&amp;gt;httpswwwroot) {echo $CFG-&amp;gt;httpswwwroot;} else {echo $CFG-&amp;gt;wwwroot;} ?&amp;gt;&lt;br /&gt;
  /blocks/accessibility/userstyles.php&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
As of Moodle 2, the block requires no additional configuration to get per-user style modifications working. Since 2.0 the block includes [http://access.ecs.soton.ac.uk/ToolBar/ ATbar], which provides Text-To-Speech functionality (TTS). To get TTS working, you&#039;ll need to follow these instructions (currently only supported on Linux servers).&lt;br /&gt;
#Install the Accessibility block as normal&lt;br /&gt;
#Install Festival, the Text-To-Speech engine, on your server. This should install text2wave in /usr/bin. If not, you&#039;ll need to symlink it there.&lt;br /&gt;
#Install LAME, the MP3 utilities, on your server.&lt;br /&gt;
#Go to the Moodle root directory (at command line or in a file manager)&lt;br /&gt;
#From here, find blocks/accessibility/toolbar/server/TTS/SB_generateAudio.sh and make it executable. To do this from the terminal, run: &amp;lt;pre&amp;gt;chmod +x blocks/accessibility/toolbar/server/TTS/SB_generateAudio.sh&amp;lt;/pre&amp;gt;&lt;br /&gt;
#Edit SB_generateAudio.sh to set the tmpdir variable at the top to a suitable temporary directory, and dirroot to the value of $CFG-&amp;gt;dirroot in your Moodle config.php&lt;br /&gt;
#Change the ownership of blocks/accessibility/toolbar/server/TTS/cache to make it writable by the user the web server runs as. To do this on Ubuntu, run these commands: &amp;lt;pre&amp;gt;chown -R user:www-data blocks/accessibility/toolbar/server/TTS/cache&amp;lt;/pre&amp;gt;  &amp;lt;pre&amp;gt;chmod -R 775 blocks/accessibility/toolbar/server/TTS/cache&amp;lt;/pre&amp;gt;&lt;br /&gt;
#Load a Moodle page containing the block, click &amp;quot;Launch ATbar&amp;quot;, select some text, and click the Text-To-Speech button (speaker icon).&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
The block&#039;s functionality is split into 2 areas: Native functions, and those functions provided bt ATbar.&lt;br /&gt;
=== Native Functions ===&lt;br /&gt;
There are 8 buttons on the block itself. The 3 buttons on the top row displaying an &#039;&#039;A&#039;&#039; control text size:&lt;br /&gt;
*Clicking [[Image:Accessibility_A-.png]] will decrease the text size.&lt;br /&gt;
*Clicking [[Image:Accessibility_A+.png]] will increase the text size.&lt;br /&gt;
*Clicking [[Image:Accessibility_A.png]] will reset the text size. If you had a saved setting for the text size, this will be cleared.&lt;br /&gt;
&lt;br /&gt;
The final button on the top row saves styles changed by the block. Once you have altered the text size or colour scheme, the button will become active, shown by the blue arrow. When it&#039;s active, click [[Image:Accessibility_save.png]] to save settings. Once saved, they will persist between pages even when you log out.&lt;br /&gt;
&lt;br /&gt;
The bottom row contains 4 buttons, each displaying a different colour scheme. Clicking any of these buttons [[Image:Accessibility_colours.png]] will apply that colour scheme to the page. Clicking the button on the far left will reset the scheme to default and clear any saved colour settings.&lt;br /&gt;
&lt;br /&gt;
=== ATbar ===&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
At the bottom of the block, you&#039;ll see a button labelled &#039;&#039;Launch ATbar&#039;&#039; and a checkbox labelled &#039;&#039;(always?)&#039;&#039;\\&lt;br /&gt;
[[Image:Accessibility_atbar.png]]&lt;br /&gt;
Clicking the button will launch ATbar and hide the native controls. ATbar has several advanced Accessibility functions on top of the ability to change page styles, including Text-To-Speech and Dictionary lookup. Note that if you change styles with ATbar, they will &#039;&#039;&#039;not&#039;&#039;&#039; persist between pages as they do with the native functions, nor are you currently able to save them.&lt;br /&gt;
Ticking the checkbox will cause ATbar to be automatically loaded each time you visit a page containing the Accessibility block.&lt;br /&gt;
You can find out more about ATbar&#039;s functions by clicking the [[Image:Accessibility_help.png]] icon on the right of the bar itself.&lt;br /&gt;
&lt;br /&gt;
[[Category:Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:Accessibility_help.png&amp;diff=80604</id>
		<title>File:Accessibility help.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:Accessibility_help.png&amp;diff=80604"/>
		<updated>2011-01-18T14:13:01Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:Accessibility_atbar.png&amp;diff=80603</id>
		<title>File:Accessibility atbar.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:Accessibility_atbar.png&amp;diff=80603"/>
		<updated>2011-01-18T14:03:25Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Accessibility block ATbar contols&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Accessibility block ATbar contols&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:Accessibility_colours.png&amp;diff=80602</id>
		<title>File:Accessibility colours.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:Accessibility_colours.png&amp;diff=80602"/>
		<updated>2011-01-18T14:03:08Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Accessibility block colour scheme button&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Accessibility block colour scheme button&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:Accessibility_save.png&amp;diff=80601</id>
		<title>File:Accessibility save.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:Accessibility_save.png&amp;diff=80601"/>
		<updated>2011-01-18T14:02:43Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Accessibility block save button&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Accessibility block save button&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:Accessibility_A%2B.png&amp;diff=80600</id>
		<title>File:Accessibility A+.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:Accessibility_A%2B.png&amp;diff=80600"/>
		<updated>2011-01-18T14:02:19Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Accessibility block increase text size button&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Accessibility block increase text size button&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:Accessibility_A-.png&amp;diff=80599</id>
		<title>File:Accessibility A-.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:Accessibility_A-.png&amp;diff=80599"/>
		<updated>2011-01-18T14:02:06Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Accessibility block decrease text size button&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Accessibility block decrease text size button&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=File:Accessibility_A.png&amp;diff=80598</id>
		<title>File:Accessibility A.png</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=File:Accessibility_A.png&amp;diff=80598"/>
		<updated>2011-01-18T14:01:31Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Accessibility Block Text size reset button&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Accessibility Block Text size reset button&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Quick_Find_List_Block&amp;diff=80596</id>
		<title>Quick Find List Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Quick_Find_List_Block&amp;diff=80596"/>
		<updated>2011-01-18T13:36:59Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This block allows users to be found quickly by use of AJAX searching.&lt;br /&gt;
If Javascript is not available, it will fall back to use PHP forms.&lt;br /&gt;
&lt;br /&gt;
=== Configuration options: ===&lt;br /&gt;
&lt;br /&gt;
When it is first added to a page, it will be configured to search All Users. Configure the block as below to narrow this down by role.&lt;br /&gt;
&lt;br /&gt;
The first option is the role the the searched users are to have; if the block is in a course it will find users with that role assigned in that course (not inherited), if it is on the front page/my moodle it will search for users with that role anywhere.&lt;br /&gt;
&lt;br /&gt;
The second option allows you to define the text to display for each user. This can be any combination of their First name, Last name and Username. Enter the place holders as described on the form to define the format.&lt;br /&gt;
&lt;br /&gt;
The third option allows the list to link to a page other than the users&#039; profiles, for example setting it to &amp;quot;http://your.moodle.site/blog/index.php?userid=&amp;quot; would make all the links point to the users&#039; blogs.&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
To use it just start typing any part of the users name into the box, as you type the list of names will appear and be narrowed down. Once you can see the user you want to find just click on their name.&lt;br /&gt;
&lt;br /&gt;
[[Category:Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Quick_Course_List_Block&amp;diff=80595</id>
		<title>Quick Course List Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Quick_Course_List_Block&amp;diff=80595"/>
		<updated>2011-01-18T13:36:35Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This block allows courses to accessed quickly by use of AJAX searching.&lt;br /&gt;
If Javascript is not available, it will fall back to use PHP forms.&lt;br /&gt;
&lt;br /&gt;
This block requires no configuration.&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
Start typing the Full Name or Short Name of the course you wish to find. The results will be narrowed down as you type. When the course you want to access is displayed, simply click the link.&lt;br /&gt;
&lt;br /&gt;
The search also supports SQL-Style wildcards: &amp;lt;tt&amp;gt;_&amp;lt;/tt&amp;gt; will match 1 character, &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; will match any number of characters. E.G. to match courses starting with &amp;lt;tt&amp;gt;A1C&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;A2C&amp;lt;/tt&amp;gt;, you could enter &amp;lt;tt&amp;gt;A_C&amp;lt;/tt&amp;gt;. You only need to use &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; if you require a wildcard in the middle of a string - they are implied at the start and the end (so searching for &amp;lt;tt&amp;gt;SCI&amp;lt;/tt&amp;gt; is the same as &amp;lt;tt&amp;gt;%SCI%&amp;lt;/tt&amp;gt;). If you wish to search for a literal &amp;lt;tt&amp;gt;_&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; precede them with a &amp;lt;tt&amp;gt;\&amp;lt;/tt&amp;gt;, so to find a course name containing &amp;lt;tt&amp;gt;A_C&amp;lt;/tt&amp;gt; you&#039;d enter &amp;lt;tt&amp;gt;A\_C&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Quick_Course_List_Block&amp;diff=80594</id>
		<title>Quick Course List Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Quick_Course_List_Block&amp;diff=80594"/>
		<updated>2011-01-18T13:35:36Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: New page: This block allows courses to accessed quickly by use of AJAX searching. If Javascript is not available, it will fall back to use PHP forms.  This block requires no configuration.  ===Usage...&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This block allows courses to accessed quickly by use of AJAX searching.&lt;br /&gt;
If Javascript is not available, it will fall back to use PHP forms.&lt;br /&gt;
&lt;br /&gt;
This block requires no configuration.&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
Start typing the Full Name or Short Name of the course you wish to find. The results will be narrowed down as you type. When the course you want to access is displayed, simply click the link.&lt;br /&gt;
&lt;br /&gt;
The search also supports SQL-Style wildcards: &amp;lt;tt&amp;gt;_&amp;lt;/tt&amp;gt; will match 1 character, &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; will match any number of characters. E.G. to match courses starting with &amp;lt;tt&amp;gt;A1C&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;A2C&amp;lt;/tt&amp;gt;, you could enter &amp;lt;tt&amp;gt;A_C&amp;lt;/tt&amp;gt;. You only need to use &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; if you require a wildcard in the middle of a string - they are implied at the start and the end (so searching for &amp;lt;tt&amp;gt;SCI&amp;lt;/tt&amp;gt; is the same as &amp;lt;tt&amp;gt;%SCI%&amp;lt;/tt&amp;gt;). If you wish to search for a literal &amp;lt;tt&amp;gt;_&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;%&amp;lt;/tt&amp;gt; precede them with a &amp;lt;tt&amp;gt;\&amp;lt;/tt&amp;gt;, so to find a course name containing &amp;lt;tt&amp;gt;A_C&amp;lt;/tt&amp;gt; you&#039;d enter &amp;lt;tt&amp;gt;A\_C&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[Category:Blocks]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Quick_Find_List_Block&amp;diff=80593</id>
		<title>Quick Find List Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Quick_Find_List_Block&amp;diff=80593"/>
		<updated>2011-01-18T13:21:13Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* Configuration options: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This block allows users to be found quickly by use of AJAX searching.&lt;br /&gt;
If Javascript is not available, it will fall back to use PHP forms.&lt;br /&gt;
&lt;br /&gt;
=== Configuration options: ===&lt;br /&gt;
&lt;br /&gt;
When it is first added to a page, it will be configured to search All Users. Configure the block as below to narrow this down by role.&lt;br /&gt;
&lt;br /&gt;
The first option is the role the the searched users are to have; if the block is in a course it will find users with that role assigned in that course (not inherited), if it is on the front page/my moodle it will search for users with that role anywhere.&lt;br /&gt;
&lt;br /&gt;
The second option allows you to define the text to display for each user. This can be any combination of their First name, Last name and Username. Enter the place holders as described on the form to define the format.&lt;br /&gt;
&lt;br /&gt;
The third option allows the list to link to a page other than the users&#039; profiles, for example setting it to &amp;quot;http://your.moodle.site/blog/index.php?userid=&amp;quot; would make all the links point to the users&#039; blogs.&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
To use it just start typing any part of the users name into the box, as you type the list of names will appear and be narrowed down. Once you can see the user you want to find just click on their name.&lt;br /&gt;
&lt;br /&gt;
[[Category:Blocks]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=blocks/quickfindlist&amp;diff=80592</id>
		<title>blocks/quickfindlist</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=blocks/quickfindlist&amp;diff=80592"/>
		<updated>2011-01-18T13:15:53Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Redirecting to Quick Find List Block&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[Quick Find List Block]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Quick_Find_List_Block&amp;diff=80591</id>
		<title>Quick Find List Block</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Quick_Find_List_Block&amp;diff=80591"/>
		<updated>2011-01-18T13:15:38Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Created page based on old blocks/quickfindlist page. Moved to bring in line with other pages in Blocks category.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This block allows users to be found quickly by use of AJAX searching.&lt;br /&gt;
If Javascript is not available, it will fall back to use PHP forms.&lt;br /&gt;
&lt;br /&gt;
=== Configuration options: ===&lt;br /&gt;
&lt;br /&gt;
When it is first added to a page, it will be configured to search All Users. Configure the block as below to narrow this down by role.&lt;br /&gt;
&lt;br /&gt;
The first option is the role the the searched users are to have; if the block is in a course it will find users with that role assigned in that course (not inherited), if it is on the front page/my moodle it will search for users with that role anywhere.&lt;br /&gt;
&lt;br /&gt;
The second option is optional; it allows the list to link to a page other than the users&#039; profiles, for example setting it to &amp;quot;http://your.moodle.site/blog/index.php?userid=&amp;quot; would make all the links point to the users&#039; blogs.&lt;br /&gt;
&lt;br /&gt;
===Usage===&lt;br /&gt;
&lt;br /&gt;
To use it just start typing any part of the users name into the box, as you type the list of names will appear and be narrowed down. Once you can see the user you want to find just click on their name.&lt;br /&gt;
&lt;br /&gt;
[[Category:Blocks]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development_talk:Module_visibility_and_display&amp;diff=79759</id>
		<title>Development talk:Module visibility and display</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development_talk:Module_visibility_and_display&amp;diff=79759"/>
		<updated>2010-12-23T14:38:53Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: /* Can this be used to create public/private course sites? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;UCLA is very excited about this feature.  Currently we are using a patch that we call public/private (http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=2768) to accomplish this functionality.&lt;br /&gt;
&lt;br /&gt;
This proposed feature would remove the need to maintain our customized code.&lt;br /&gt;
&lt;br /&gt;
Additionally, allowing the developers to add custom editing icons next to resources/activities without modifying core moodle is an excellent idea!&lt;br /&gt;
--[[User:Nick Thompson|Nick Thompson]] 17:37, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
------&lt;br /&gt;
+1 from me.--[[User:Tim Hunt|Tim Hunt]] 18:39, 15 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==A few comments==&lt;br /&gt;
# the modinfo could be a class with extra methods for the new stuff - instead of precalculating everything we could do the extra work only when necessary, it should be 100% compatible with current code and it could actually detect some parameter problems; another reason is there is no proper phpdocs which prevents autocomplete from working in IDEs&lt;br /&gt;
# icon and iconcomponent are supposed to be the new api, the mod/mymodule/iconname hack should be deprecated instead&lt;br /&gt;
# at the same time we should fix the known perf problems with the modinfo caching&lt;br /&gt;
&lt;br /&gt;
Alternative proposal:&lt;br /&gt;
* create new interface module_info which is backwards compatible with old $cminfo, add hidden setting which specifies which class to use&lt;br /&gt;
* keep get_fast_modinfo() and make it return array of instances with module_info interface&lt;br /&gt;
* either use plugin_supports() for finding out if plugin contains view.php (false means no url, true default) - external urls and nonstandard urls are supposed to be implemented via view.php redirects such as in the mod/url&lt;br /&gt;
* or simply check if mod/xx/view.php exists (did we ever consider this solution?)&lt;br /&gt;
* all course page specific data could be initialised/computed only when necessary&lt;br /&gt;
&lt;br /&gt;
Benefits could be a bit better performance, smaller course-&amp;gt;modinfo and finally all the customisation could be done via modification/replacement of one class only.&lt;br /&gt;
&lt;br /&gt;
--[[User:Petr Škoda (škoďák)|Petr Škoda (škoďák)]] 16:56, 19 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Can this be used to create public/private course sites? ==&lt;br /&gt;
&lt;br /&gt;
I&#039;m not following all of this, but want to ask if this change would allow either of the following:&lt;br /&gt;
&lt;br /&gt;
1. Guests can see course site, but certain resources or activities are invisible (and unavailable) unless logged in and enrolled in that class.  (This is the purpose of UCLA&#039;s public/private customization mentioned by Nick Thompson above. We do this through Groupings and defaulting the course to public.)&lt;br /&gt;
&lt;br /&gt;
2. Guests can NOT see the course site, but CAN access specific resources or activities if they&#039;ve been marked as public and they have a URL to get there. (This is not how UCLA&#039;s is set up, but conceivably might be useful in certain situations.)&lt;br /&gt;
&lt;br /&gt;
--Mike Franks 21:30, 22 December 2010 (UTC)&lt;br /&gt;
&lt;br /&gt;
== Yes Please ==&lt;br /&gt;
Just to add that I think this is a fantastic idea. I was hoping to be able to do this with my Standard Slideshow module (allowing the slideshow to be optionally embedded directly on the course page, rather than just a separate view page).&lt;br /&gt;
&lt;br /&gt;
[[User:Mark Johnson|Mark Johnson]] 14:38, 23 December 2010 (UTC)&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:lib/formslib.php_Form_Definition&amp;diff=79148</id>
		<title>Development:lib/formslib.php Form Definition</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:lib/formslib.php_Form_Definition&amp;diff=79148"/>
		<updated>2010-12-14T11:34:24Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Added documentation of filepicker with link to File API page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Formslib}}&lt;br /&gt;
== &#039;&#039;definition()&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
The definition of the elements to be included in the form, their &#039;types&#039; (PARAM_*), helpbuttons included, etc. is all included in a function you must define in your class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;definition()&#039;&#039; is used to define the elements in the form and &#039;&#039;&#039;this definition will be used for validating data submitted as well as for printing the form.&#039;&#039;&#039; For select and checkbox type elements only data that could have been selected will be allowed. And only data that corresponds to a form element in the definition will be accepted as submitted data.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;definition()&#039;&#039; should include all elements that are going to be used on form, some elements may be removed or tweaked later in &#039;&#039;definition_after_data()&#039;&#039;. Please do not create conditional elements in &#039;&#039;definition()&#039;&#039;, the definition() should not directly depend on the submitted data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once(&amp;quot;$CFG-&amp;gt;libdir/formslib.php&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
class simplehtml_form extends moodleform {&lt;br /&gt;
&lt;br /&gt;
    function definition() {&lt;br /&gt;
        global $CFG;&lt;br /&gt;
       &lt;br /&gt;
        $mform =&amp;amp; $this-&amp;gt;_form; // Don&#039;t forget the underscore! &lt;br /&gt;
&lt;br /&gt;
        $mform-&amp;gt;addElement()... // Add elements to your form&lt;br /&gt;
            ...&lt;br /&gt;
    }                           // Close the function&lt;br /&gt;
}                               // Close the class&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use Fieldsets to group Form Elements==&lt;br /&gt;
&lt;br /&gt;
You use code like this to open a fieldset with a &#039;&#039;legend&#039;&#039;. &amp;lt;br /&amp;gt;&lt;br /&gt;
(&#039;&#039;&#039;Note&#039;&#039;&#039;: Some themes turn off legends on admin setting pages by using CSS: &amp;lt;nowiki&amp;gt;#adminsettings legend {display:none;}&amp;lt;/nowiki&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;header&#039;, &#039;nameforyourheaderelement&#039;, get_string(&#039;titleforlegened&#039;, &#039;modulename&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can&#039;t yet nest these visible fieldsets unfortunately. But in fact groups of elements are wrapped in invisible fieldsets.&lt;br /&gt;
&lt;br /&gt;
You close a fieldset with moodle_form&#039;s closeHeaderBefore method. You tell closeHeaderBefore the element before you wish to end the fieldset. A fieldset is automatically closed if you open a new one. You need to use this code only if you want to close a fieldset and the subsequent form elements are not to be enclosed by a visible fieldset (they are still enclosed with an invisibe one with no legend) :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;closeHeaderBefore(&#039;buttonar&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==addElement==&lt;br /&gt;
&lt;br /&gt;
Use the addElement method to add an element to a form. The first few arguments are always the same. The first param is the type of the element to add. The second is the elementname to use which is normally the html name of the element in the form. The third is often the text for the label for the element.&lt;br /&gt;
&lt;br /&gt;
Some examples are below :&lt;br /&gt;
=== button ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;button&#039;, &#039;intro&#039;, get_string(&amp;quot;buttonlabel&amp;quot;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A button element. If you want a submit or cancel button see &#039;submit&#039; element.&lt;br /&gt;
&lt;br /&gt;
=== checkbox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;checkbox&#039;, &#039;ratingtime&#039;, get_string(&#039;ratingtime&#039;, &#039;forum&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a simple checkbox. The third parameter for this element is the label to display on the left side of the form. You can also supply a string as a fourth parameter to specify a label that will appear on the right of the element. Checkboxes and radio buttons can be grouped and have individual labels on their right.&lt;br /&gt;
&lt;br /&gt;
You can have a 5th parameter $attributes, as on other elements.&lt;br /&gt;
&lt;br /&gt;
==== advcheckbox ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;advcheckbox&#039;, &#039;ratingtime&#039;, get_string(&#039;ratingtime&#039;, &#039;forum&#039;), &#039;Label displayed after checkbox&#039;, array(&#039;group&#039; =&amp;gt; 1), array(0, 1));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar to the checkbox above, but with a couple of important improvements:&lt;br /&gt;
&lt;br /&gt;
# The 5th parameter is a normal $attributes array, normally used to set HTML attributes for the &amp;lt;input&amp;gt; element. However, a special value of &#039;group&#039; can be given, which will add a class name to the element, and enable its grouping for a [[Development:lib/formslib.php_add_checkbox_controller|checkbox controller]]&lt;br /&gt;
#The 6th parameter is an array of values that will be associated with the checked/unchecked state of the checkbox. With a normal checkbox you cannot choose that value, and in fact an unchecked checkbox will not even be sent with the form data.&lt;br /&gt;
&lt;br /&gt;
=== choosecoursefile ===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;choosecoursefile&#039;, &#039;mediafile&#039;, get_string(&#039;mediafile&#039;, &#039;lesson&#039;), array(&#039;courseid&#039;=&amp;gt;$COURSE-&amp;gt;id));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose a file from the course files area. The fourth option is a list of options for the element. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
array(&#039;courseid&#039; =&amp;gt;null,  //if it is null (default then use global $COURSE&lt;br /&gt;
      &#039;height&#039;   =&amp;gt;500,   // height of the popup window&lt;br /&gt;
      &#039;width&#039;    =&amp;gt;750,   // width of the popup window&lt;br /&gt;
      &#039;options&#039;  =&amp;gt;&#039;none&#039;); //options string for the pop up window &lt;br /&gt;
                          //eg. &#039;menubar=0,location=0,scrollbars,resizable&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also pass an optional 5th parameter of attributes, as for other elements. The most useful way of using that is something like &lt;br /&gt;
&amp;lt;code php&amp;gt;array(&#039;maxlength&#039; =&amp;gt; 255, &#039;size&#039; =&amp;gt; 48)&amp;lt;/code&amp;gt;&lt;br /&gt;
to control the maxlength / size of the text box (note size will default to 48 if not specified)&lt;br /&gt;
&lt;br /&gt;
Finally, as this element is a group containing two elements (button + value), you can add validation rules by using the &#039;&#039;&#039;addGroupRule()&#039;&#039;&#039; method in this (complex) way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;$mform-&amp;gt;addGroupRule(&#039;elementname&#039;, array(&#039;value&#039; =&amp;gt; array(array(list, of, rule, params, but, fieldname))));&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where: &#039;&#039;&#039;&amp;quot;elementname&amp;quot;&#039;&#039;&#039; is the name of the choosecoursefile group element, &#039;&#039;&#039;&amp;quot;value&amp;quot;&#039;&#039;&#039; is the name of the text field within the group and the &#039;&#039;&#039;&amp;quot;list, of, addrule, params, but, fieldname&amp;quot;&#039;&#039;&#039; is exactly that, the list of fields in the normal addRule() function but ommiting the first one, the fieldname.&lt;br /&gt;
&lt;br /&gt;
For example, the [http://cvs.moodle.org/moodle/mod/resource/type/file/resource.class.php?view=markup file/url resource type], uses one &amp;quot;choosecoursefile&amp;quot; element, and it controls the maximum length of the field (255) with this use of addGroupRule():&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;$mform-&amp;gt;addGroupRule(&#039;reference&#039;, array(&#039;value&#039; =&amp;gt; array(array(get_string(&#039;maximumchars&#039;, &#039;&#039;, 255), &#039;maxlength&#039;, 255, &#039;client&#039;))));&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== date_selector ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;date_selector&#039;, &#039;assesstimefinish&#039;, get_string(&#039;to&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a date selector. You can select a Day, Month and Year using a group of select boxes. The fourth param here is an array of options. The defaults for the options are :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
array(&lt;br /&gt;
    &#039;startyear&#039; =&amp;gt; 1970, &lt;br /&gt;
    &#039;stopyear&#039;  =&amp;gt; 2020,&lt;br /&gt;
    &#039;timezone&#039;  =&amp;gt; 99, &lt;br /&gt;
    &#039;applydst&#039;  =&amp;gt; true, &lt;br /&gt;
    &#039;optional&#039;  =&amp;gt; false&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can override these defaults by supplying an array as fourth param with one or more keys with a value to override the default. You can supply a fifth param of attributes here as well.&lt;br /&gt;
&lt;br /&gt;
=== date_time_selector ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;date_time_selector&#039;, &#039;assesstimestart&#039;, get_string(&#039;from&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a group of select boxes to select a date (Day Month and Year) and time (Hour and Minute). When submitted, submitted data is processed and a timestamp is passed to $form-&amp;gt;get_data(); the fourth param here is an array of options. The defaults for the options are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
array(&lt;br /&gt;
    &#039;startyear&#039; =&amp;gt; 1970, &lt;br /&gt;
    &#039;stopyear&#039;  =&amp;gt; 2020,&lt;br /&gt;
    &#039;timezone&#039;  =&amp;gt; 99, &lt;br /&gt;
    &#039;applydst&#039;  =&amp;gt; true, &lt;br /&gt;
    &#039;step&#039;      =&amp;gt; 5&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can override these defaults by supplying an array as fourth param with one or more keys with a value to override the default. You can supply a fifth param of attributes here as well.&lt;br /&gt;
&lt;br /&gt;
===duration===&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;duration&#039;, &#039;timelimit&#039;, get_string(&#039;timelimit&#039;, &#039;quiz&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This field type lets the user input an interval of time. It comprises a text field, where you can type a number, and a dropdown for selecting a unit (days, hours, minutes or seconds). When submitted the value is converted to a number of seconds.&lt;br /&gt;
&lt;br /&gt;
You can add a fourth parameter to give options. At the moment the only option supported is here is an array of options. The defaults for the options is:&lt;br /&gt;
&amp;lt;code php&amp;gt;array(&#039;optional&#039; =&amp;gt; true)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also pass an optional 5th parameter of attributes, as for other elements. The most useful way of using that is something like &lt;br /&gt;
&amp;lt;code php&amp;gt;array(&#039;size&#039; =&amp;gt; 5)&amp;lt;/code&amp;gt;&lt;br /&gt;
to control the size of the text box.&lt;br /&gt;
&lt;br /&gt;
=== file ===&lt;br /&gt;
&lt;br /&gt;
File upload input box with browse button. In the form definition type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;file&#039;, &#039;attachment&#039;, get_string(&#039;attachment&#039;, &#039;forum&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
after form submission and validation use&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if ($data = $mform-&amp;gt;get_data()) {&lt;br /&gt;
      ...&lt;br /&gt;
    $mform-&amp;gt;save_files($destination_directory);&lt;br /&gt;
      ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need advanced settings such as required file, different max upload size or name of uploaded file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$this-&amp;gt;set_upload_manager(new upload_manager(&#039;attachment&#039;, true, false, $COURSE, false, 0, true, true, false));&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;file&#039;, &#039;attachment&#039;, get_string(&#039;attachment&#039;, &#039;forum&#039;));&lt;br /&gt;
            $mform-&amp;gt;addRule(&#039;attachment&#039;, null, &#039;required&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if ($data = $mform-&amp;gt;get_data()) {&lt;br /&gt;
      ...&lt;br /&gt;
    $mform-&amp;gt;save_files($destination_directory);&lt;br /&gt;
    $newfilename = $mform-&amp;gt;get_new_filename();&lt;br /&gt;
      ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When porting old code it is also possible to use the upload manager directly for processing of uploaded files.&lt;br /&gt;
&lt;br /&gt;
Please note that if using set_upload_manager() it must be before addElement(&#039;file&#039;,..).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
File uploading was rewritten in 2.0. Please see inline docs for now. This page will be updated when the new API stabilises.&lt;br /&gt;
&lt;br /&gt;
===filepicker===&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
General replacement of &#039;&#039;file&#039;&#039; element.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;filepicker&#039;, &#039;userfile&#039;, get_string(&#039;file&#039;), null, array(&#039;maxbytes&#039; =&amp;gt; $maxbytes, &#039;accepted_types&#039; =&amp;gt; &#039;*&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
See also [[Development:Using the File API in Moodle forms]]&lt;br /&gt;
&lt;br /&gt;
=== hidden ===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;hidden&#039;, &#039;reply&#039;, &#039;yes&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A hidden element. Set the element name (in this case &#039;&#039;&#039;reply&#039;&#039;&#039;) to the stated value (in this case &#039;&#039;&#039;yes&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
=== html ===&lt;br /&gt;
You can add arbitrary HTML to your Moodle form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;html&#039;, &#039;&amp;lt;div class=&amp;quot;qheader&amp;quot;&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See [http://moodle.org/mod/forum/discuss.php?d=126935 &amp;quot;Question: Can I put a moodleform inside a table td?&amp;quot;] for a concrete example.&lt;br /&gt;
&lt;br /&gt;
=== htmleditor &amp;amp; format ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;htmleditor&#039;, &#039;text&#039;, get_string(&#039;choicetext&#039;, &#039;choice&#039;));&lt;br /&gt;
$mform-&amp;gt;setType(&#039;text&#039;, PARAM_RAW);&lt;br /&gt;
$mform-&amp;gt;addRule(&#039;text&#039;, null, &#039;required&#039;, null, &#039;client&#039;);&lt;br /&gt;
&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;format&#039;, &#039;format&#039;, get_string(&#039;format&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can supply a fourth param to htmleditor of an array of options :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&lt;br /&gt;
array(&lt;br /&gt;
    &#039;canUseHtmlEditor&#039;=&amp;gt;&#039;detect&#039;,&lt;br /&gt;
    &#039;rows&#039;  =&amp;gt; 10, &lt;br /&gt;
    &#039;cols&#039;  =&amp;gt; 65, &lt;br /&gt;
    &#039;width&#039; =&amp;gt; 0,&lt;br /&gt;
    &#039;height&#039;=&amp;gt; 0, &lt;br /&gt;
    &#039;course&#039;=&amp;gt; 0,&lt;br /&gt;
);&lt;br /&gt;
//options same as print_textarea params&lt;br /&gt;
//use rows and cols options to control htmleditor size.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===modgrade===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;modgrade&#039;, &#039;scale&#039;, get_string(&#039;grade&#039;), false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a custom element for selecting a grade for any activity module. The fourth argument is whether to include an option for no grade which has a value 0. This select box does include scales. The default is true, include no grade option.&lt;br /&gt;
&lt;br /&gt;
A helpbutton is automatically added.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===password===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         $mform-&amp;gt;addElement(&#039;password&#039;, &#039;password&#039;, get_string(&#039;label&#039;), $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A password element. Fourth param is an array or string of attributes.&lt;br /&gt;
&lt;br /&gt;
===passwordunmask===&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         $mform-&amp;gt;addElement(&#039;passwordunmask&#039;, &#039;password&#039;, get_string(&#039;label&#039;), $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A password element with option to show the password in plaintext. Fourth param is an array or string of attributes.&lt;br /&gt;
&lt;br /&gt;
=== radio ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$radioarray=array();&lt;br /&gt;
$radioarray[] = &amp;amp;MoodleQuickForm::createElement(&#039;radio&#039;, &#039;yesno&#039;, &#039;&#039;, get_string(&#039;yes&#039;), 1, $attributes);&lt;br /&gt;
$radioarray[] = &amp;amp;MoodleQuickForm::createElement(&#039;radio&#039;, &#039;yesno&#039;, &#039;&#039;, get_string(&#039;no&#039;), 0, $attributes);&lt;br /&gt;
$mform-&amp;gt;addGroup($radioarray, &#039;radioar&#039;, &#039;&#039;, array(&#039; &#039;), false);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Second param names the radio button and should be the same for each button in the group in order to toggle correctly. Third param would be the label for the form element but is generally ignored as this element will always be in a group which has it&#039;s own label. Fourth param is a string, a label to be displayed on the right of the element. The fifth is the value for this radio button. $attributes can be a string or an array of attributes.&lt;br /&gt;
&lt;br /&gt;
It is possible to add help to individual radio buttons but this requires a custom template to be defined for the group elements. See MDL-15571.&lt;br /&gt;
&lt;br /&gt;
==== setDefault ====&lt;br /&gt;
&lt;br /&gt;
To set the default for a radio button group as above use the following :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;setDefault(&#039;yesno&#039;, 0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would make the default &#039;no&#039;.&lt;br /&gt;
&lt;br /&gt;
===select===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;select&#039;, &#039;type&#039;, get_string(&#039;forumtype&#039;, &#039;forum&#039;), $FORUM_TYPES, $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The fourth param for this element is an array of options for the select box. The keys are the values for the option and the value of the array is the text for the option. The fifth param $attributes is optional, see text element for description of attributes param.&lt;br /&gt;
&lt;br /&gt;
It is also possible to create a select with certain options disabled, using [http://stackoverflow.com/questions/2138089/how-can-i-use-quickform-to-add-disabled-select-options/2150275#2150275 this technique].&lt;br /&gt;
&lt;br /&gt;
====multi-select====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $select = &amp;amp;$mform-&amp;gt;addElement(&#039;select&#039;, &#039;colors&#039;, get_string(&#039;colors&#039;), array(&#039;red&#039;, &#039;blue&#039;, &#039;green&#039;), $attributes);&lt;br /&gt;
        $select-&amp;gt;setMultiple(true);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===selectyesno===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;selectyesno&#039;, &#039;maxbytes&#039;, get_string(&#039;maxattachmentsize&#039;, &#039;forum&#039;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want a yes / no select box this one automatically translates itself and has value 1 for yes and 0 for no.&lt;br /&gt;
&lt;br /&gt;
===static===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         $mform-&amp;gt;addElement(&#039;static&#039;, &#039;description&#039;, get_string(&#039;description&#039;, &#039;exercise&#039;),&lt;br /&gt;
                  get_string(&#039;descriptionofexercise&#039;, &#039;exercise&#039;, $COURSE-&amp;gt;students));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a static element. It should be used with care it is used to display a static piece of text with a label. The third param is the label and the fourth is the static text itself.&lt;br /&gt;
&lt;br /&gt;
===submit, reset and cancel===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        //normally you use add_action_buttons instead of this code&lt;br /&gt;
        $buttonarray=array();&lt;br /&gt;
        $buttonarray[] = &amp;amp;$mform-&amp;gt;createElement(&#039;submit&#039;, &#039;submitbutton&#039;, get_string(&#039;savechanges&#039;));&lt;br /&gt;
        $buttonarray[] = &amp;amp;$mform-&amp;gt;createElement(&#039;reset&#039;, &#039;resetbutton&#039;, get_string(&#039;revert&#039;));&lt;br /&gt;
        $buttonarray[] = &amp;amp;$mform-&amp;gt;createElement(&#039;cancel&#039;);&lt;br /&gt;
        $mform-&amp;gt;addGroup($buttonarray, &#039;buttonar&#039;, &#039;&#039;, array(&#039; &#039;), false);&lt;br /&gt;
        $mform-&amp;gt;closeHeaderBefore(&#039;buttonar&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;Submit&#039; type element is a submit type form element which will submit the form. A &#039;Reset&#039; will not submit the form but will reset any changes the user has made to form contents. A &#039;Cancel&#039; element cancels form submission. You need to have a branch in your code before you check for get_data() to check if submission has been cancelled with is_cancelled(); See the example on the usage page.&lt;br /&gt;
&lt;br /&gt;
You should name your submit and reset buttons &#039;submitbutton&#039; and &#039;resetbutton&#039; or something similar (not &#039;submit&#039; and &#039;reset&#039;). This avoids problems in JavaScript of collisions between form element names and names of JavaScript methods of the form object.&lt;br /&gt;
&lt;br /&gt;
====add_action_buttons($cancel = true, $submitlabel=null);====&lt;br /&gt;
&lt;br /&gt;
You will normally use this helper function which is a method of moodleform to add all the &#039;action&#039; buttons to the end of your form. A boolean parameter allow you to specify whether to include a cancel button and specify the label for your submit button (pass the result of get_string). Default for the submit button label is get_string(&#039;savechanges&#039;).&lt;br /&gt;
&lt;br /&gt;
===text===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;text&#039;, &#039;name&#039;, get_string(&#039;forumname&#039;, &#039;forum&#039;), $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For a simple text element. Your fourth parameter here can be a string or array of attributes for the text element. The following are equivalent :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $attributes=&#039;size=&amp;quot;20&amp;quot;&#039;;&lt;br /&gt;
        $attributes=array(&#039;size&#039;=&amp;gt;&#039;20&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Generally you are encouraged to use CSS instead of using attributes for styling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A format element can be used as a format select box. It will be non-selectable if you&#039;re using an html editor.&lt;br /&gt;
&lt;br /&gt;
The third param for this element is $useHtmlEditor and it defaults to null in which case an html editor is used if the browser and user profile support it.&lt;br /&gt;
&lt;br /&gt;
===textarea===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;textarea&#039;, &#039;introduction&#039;, get_string(&amp;quot;introtext&amp;quot;, &amp;quot;survey&amp;quot;), &#039;wrap=&amp;quot;virtual&amp;quot; rows=&amp;quot;20&amp;quot; cols=&amp;quot;50&amp;quot;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A textarea element. If you want an htmleditor use htmleditor element. Fourth element here is a string or array of attributes.&lt;br /&gt;
&lt;br /&gt;
===recaptcha===&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;recaptcha&#039;, &#039;recaptcha_field_name&#039;, $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use this recaptcha element to reduce the spam risk in your forms. Third element here is a string or array of attributes. Take care to get an API key from http://recaptcha.net/api/getkey before using this element.&lt;br /&gt;
&lt;br /&gt;
To check whether recaptcha is enabled at site level use:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (!empty($CFG-&amp;gt;recaptchapublickey) &amp;amp;&amp;amp; !empty($CFG-&amp;gt;recaptchaprivatekey)) {&lt;br /&gt;
    //recaptcha is enabled&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tags===&lt;br /&gt;
&lt;br /&gt;
Moodle 2.0+ only. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;tags&#039;, &#039;field_name&#039;, $lable, $options, $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Used for editing a list of tags, for example on a blog post.&lt;br /&gt;
&lt;br /&gt;
There is only one option available, &#039;display&#039;, which should be set to one of the contstants MoodleQuickForm_tags::ONLYOFFICIAL, NOOFFICIAL or DEFAULTUI. This controls whether the official tags are listed for easy selection, or a text area where arbitrary tags may be typed, or both. The default is both.&lt;br /&gt;
&lt;br /&gt;
The value should be set/returned as an array of tags.&lt;br /&gt;
&lt;br /&gt;
==addGroup==&lt;br /&gt;
&lt;br /&gt;
A &#039;group&#039; in formslib is just a group of elements that will have a label and will be included on one line. &lt;br /&gt;
&lt;br /&gt;
For example typical code to include a submit and cancel button on the same line : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $buttonarray=array();&lt;br /&gt;
        $buttonarray[] =&amp;amp; $mform-&amp;gt;createElement(&#039;submit&#039;, &#039;submitbutton&#039;, get_string(&#039;savechanges&#039;));&lt;br /&gt;
        $buttonarray[] =&amp;amp; $mform-&amp;gt;createElement(&#039;submit&#039;, &#039;cancel&#039;, get_string(&#039;cancel&#039;));&lt;br /&gt;
        $mform-&amp;gt;addGroup($buttonarray, &#039;buttonar&#039;, &#039;&#039;, array(&#039; &#039;), false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You use the same arguments for createElement as you do for addElement. Any label for the element in the third argument is normally ignored (but not in the case of the submit buttons above where the third argument is not for a label but is the text for the button).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a bad example (don&#039;t do this for real, use the &#039;optional&#039; =&amp;gt; true option of the date element): putting a date_selector (which is itself a group of elements) and a checkbox on the same line, note that you can disable every element in the group using the group name &#039;availablefromgroup&#039; but it doesn&#039;t disable the controlling element the &#039;availablefromenabled&#039; checkbox:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $availablefromgroup=array();&lt;br /&gt;
	$availablefromgroup[] =&amp;amp; $mform-&amp;gt;createElement(&#039;date_selector&#039;, &#039;availablefrom&#039;, &#039;&#039;);&lt;br /&gt;
	$availablefromgroup[] =&amp;amp; $mform-&amp;gt;createElement(&#039;checkbox&#039;, &#039;availablefromenabled&#039;, &#039;&#039;, get_string(&#039;enable&#039;));&lt;br /&gt;
        $mform-&amp;gt;addGroup($availablefromgroup, &#039;availablefromgroup&#039;, get_string(&#039;availablefromdate&#039;, &#039;data&#039;), &#039;&amp;amp;nbsp;&#039;, false);&lt;br /&gt;
        $mform-&amp;gt;disabledIf(&#039;availablefromgroup&#039;, &#039;availablefromenabled&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==addRule==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addRule(&#039;elementname&#039;, get_string(&#039;error&#039;), &#039;rule type&#039;, &#039;extraruledata&#039;, &#039;server&#039;(default), false, false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first param(element) is an element name and second(message) is the error message that will be displayed to the user.&lt;br /&gt;
The third parameter(type) is the type of rule. The fourth param(format) is used for extra data needed with some rules such as minlength and regex. The fifth parameter(validation) validates input data on server or client side, if validation is done on client side then it will be checked on the server side as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * @param    string     $element       Form element name&lt;br /&gt;
 * @param    string     $message       Message to display for invalid data&lt;br /&gt;
 * @param    string     $type          Rule type, use getRegisteredRules() to get types&lt;br /&gt;
 * @param    string     $format        (optional)Required for extra rule data&lt;br /&gt;
 * @param    string     $validation    (optional)Where to perform validation: &amp;quot;server&amp;quot;, &amp;quot;client&amp;quot;&lt;br /&gt;
 * @param    boolean    $reset         Client-side validation: reset the form element to its original value if there is an error?&lt;br /&gt;
 * @param    boolean    $force         Force the rule to be applied, even if the target form element does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Common Rule Types&#039;&#039;&#039;&lt;br /&gt;
* required &lt;br /&gt;
* maxlength&lt;br /&gt;
* minlength&lt;br /&gt;
* rangelength&lt;br /&gt;
* email&lt;br /&gt;
* regex&lt;br /&gt;
* lettersonly&lt;br /&gt;
* alphanumeric&lt;br /&gt;
* numeric&lt;br /&gt;
* nopunctuation&lt;br /&gt;
* nonzero&lt;br /&gt;
* callback&lt;br /&gt;
* compare&lt;br /&gt;
&lt;br /&gt;
==setHelpButton==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;setHelpButton(&#039;lessondefault&#039;, array(&#039;lessondefault&#039;, get_string(&#039;lessondefault&#039;, &#039;lesson&#039;), &#039;lesson&#039;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First param is an elementname and the second param is an array of params that are passed to helpbutton in weblib.php. Params are :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * @param string $page  The keyword that defines a help page&lt;br /&gt;
 * @param string $title The title of links, rollover tips, alt tags etc&lt;br /&gt;
 *           &#039;Help with&#039; (or the language equivalent) will be prefixed and &#039;...&#039; will be stripped.&lt;br /&gt;
 * @param string $module Which module is the page defined in&lt;br /&gt;
 * @param mixed $image Use a help image for the link?  (true/false/&amp;quot;both&amp;quot;)&lt;br /&gt;
 * @param boolean $linktext If true, display the title next to the help icon.&lt;br /&gt;
 * @param string $text If defined then this text is used in the page, and&lt;br /&gt;
 *           the $page variable is ignored.&lt;br /&gt;
 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.&lt;br /&gt;
 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Make sure you don&#039;t set boolean $return to false. &lt;br /&gt;
&lt;br /&gt;
You need to do use this method after addElement();&lt;br /&gt;
&lt;br /&gt;
==setDefault==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;select&#039;, &#039;grade&#039;, get_string(&#039;gradeforsubmission&#039;, &#039;exercise&#039;), $grades);&lt;br /&gt;
        $mform-&amp;gt;setHelpButton(&#039;grade&#039;, array(&#039;grade&#039;, get_string(&#039;gradeforsubmission&#039;, &#039;exercise&#039;), &#039;exercise&#039;));&lt;br /&gt;
        $mform-&amp;gt;setDefault(&#039;grade&#039;, 100);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the default of the form value with setDefault($elementname, $value); where elementname is the elementname whose default you want to set and $value is the default to set. We set the defaults for the form in definition(). This default is what is used if no data is loaded into the form with set_data(); eg. on display of the form for an &#039;add&#039; rather than &#039;update&#039; function.&lt;br /&gt;
&lt;br /&gt;
==disabledIf==&lt;br /&gt;
&lt;br /&gt;
For any element or groups of element in a form you can conditionally disable the group or individual element depending on conditions.&lt;br /&gt;
&lt;br /&gt;
You can use $mform-&amp;gt;disabledIf($elementName, $dependentOn, $condition = &#039;notchecked&#039;, $value=null)&lt;br /&gt;
&lt;br /&gt;
* elementname can be a group. If you specify a group all elements in the group will be disabled (if dependentOn is in elementname group that is ignored and not disabled). These are the element names you&#039;ve used as the second argument in addElement or addGroup.&lt;br /&gt;
* dependentOn is the actual name of the element as it will appear in html. This can be different to the name used in addGroup particularly but also addElement where you&#039;re adding a complex element like a date_selector. Check the html of your page. You typically make the depedentOn a checkbox or select box.&lt;br /&gt;
* $condition will be &#039;notchecked&#039;, &#039;checked&#039;, &#039;noitemselected&#039;, &#039;eq&#039; or, if it is anything else, we test for &#039;neq&#039;.&lt;br /&gt;
** If $condition is &#039;eq&#039; or &#039;neq&#039; then we check the value of the dependentOn field and check for equality (==) or nonequality (!=) in js&lt;br /&gt;
** If $condition is &#039;checked&#039; or &#039;notchecked&#039; then we check to see if a checkbox is checked or not.&lt;br /&gt;
** If $condition is &#039;noitemselected&#039; then we check to see whether nothing is selected in a dropdown list.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
 // Disable my control unless a checkbox is checked.&lt;br /&gt;
 $mform-&amp;gt;disabledIf(&#039;mycontrol&#039;, &#039;somecheckbox&#039;);&lt;br /&gt;
 &lt;br /&gt;
 // Disable my control if a checkbox &#039;&#039;&#039;is&#039;&#039;&#039; checked.&lt;br /&gt;
 $mform-&amp;gt;disabledIf(&#039;mycontrol&#039;, &#039;somecheckbox&#039;, &#039;checked&#039;);&lt;br /&gt;
 &lt;br /&gt;
 // Disable my control unless a dropdown has value 42.&lt;br /&gt;
 $mform-&amp;gt;disabledIf(&#039;mycontrol&#039;, &#039;someselect&#039;, &#039;eq&#039;, 42);&lt;br /&gt;
&lt;br /&gt;
The possible choices here are in the function lockoptionsall in lib/javascript-static.js.&lt;br /&gt;
&lt;br /&gt;
==setType==&lt;br /&gt;
&lt;br /&gt;
PARAM_* types are used to specify how a submitted variable should be cleaned. These should be used for get parameters such as id, course etc. which are used to load a page and also with setType(); method. Every form element should have a type specified except select, radio box and checkbox elements, these elements do a good job of cleaning themselves (only specified options are allowed as user input).&lt;br /&gt;
&lt;br /&gt;
===Most Commonly Used PARAM_* Types===&lt;br /&gt;
&lt;br /&gt;
These are the most commonly used PARAM_* types and their proper uses. More types can be seen in moodlelib.php starting around line 100.&lt;br /&gt;
&lt;br /&gt;
* PARAM_CLEAN is deprecated and you should try to use a more specific type.&lt;br /&gt;
* PARAM_TEXT should be used for cleaning data that is expected to be plain text. It will strip all html tags. But will still let tags for multilang support through.&lt;br /&gt;
* PARAM_NOTAGS should be used for cleaning data that is expected to be plain text. It will strip *all* html type tags. It will still *not* let tags for multilang support through. This should be used for instance for email addresses where no multilang support is appropriate.&lt;br /&gt;
* PARAM_RAW means no cleaning whatsoever, it is used mostly for data from the html editor. Data from the editor is later cleaned before display using format_text() function. PARAM_RAW can also be used for data that is validated by some other way or printed by p() or s().&lt;br /&gt;
* PARAM_INT should be used for integers.&lt;br /&gt;
* PARAM_ACTION is an alias of PARAM_ALPHA and is used for hidden fields specifying form actions.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://www.midnighthax.com/quickform.php PEAR HTML QuickForm Getting Started Guide] by Keith Edmunds of Midnighthax.com&lt;br /&gt;
* [http://pear.php.net/manual/en/package.html.html-quickform.php PEAR::HTML_QuickForm manual]&lt;br /&gt;
&lt;br /&gt;
[[Category:Formslib]]&lt;br /&gt;
&lt;br /&gt;
If you have problems creating php forms you may get them with form builder http://phpforms.net/tutorial/html-basics/form-builder.html&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Capabilities/moodle/course:managegrades&amp;diff=73843</id>
		<title>Capabilities/moodle/course:managegrades</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Capabilities/moodle/course:managegrades&amp;diff=73843"/>
		<updated>2010-07-12T07:59:27Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;*This capability has been defined (as of 1.7.1) to allow the user to manage grade exceptions in a given course.&lt;br /&gt;
*Grade exceptions allow the person with this capability to determine which students or assignments should or should not be present in the [[Grades|gradebook]].&lt;br /&gt;
*This appears to have been removed in Moodle 1.9. See [[Capabilities/moodle/grade:manage|moodle/grade:manage]]&lt;br /&gt;
&lt;br /&gt;
====Legacy Role Default Settings====&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;2&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! Legacy Role !! Inherit !! Allow !! Prevent !! Prohibit&lt;br /&gt;
|-&lt;br /&gt;
| Administrator || - || X || - || -&lt;br /&gt;
|-&lt;br /&gt;
| Course Creator || X || - || - || -&lt;br /&gt;
|-&lt;br /&gt;
| Teacher || - || X || - || -&lt;br /&gt;
|-&lt;br /&gt;
| Non-editing Teacher || X || - || - || -&lt;br /&gt;
|-&lt;br /&gt;
| Student || X || - || - || -&lt;br /&gt;
|-&lt;br /&gt;
| Guest || X || - || - || -&lt;br /&gt;
|-&lt;br /&gt;
| Authenticated User || X || - || - || -&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:Capabilities|Course]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=Development:lib/formslib.php_Form_Definition&amp;diff=72399</id>
		<title>Development:lib/formslib.php Form Definition</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=Development:lib/formslib.php_Form_Definition&amp;diff=72399"/>
		<updated>2010-05-25T08:13:53Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Formslib}}&lt;br /&gt;
== &#039;&#039;definition()&#039;&#039; ==&lt;br /&gt;
&lt;br /&gt;
The definition of the elements to be included in the form, their &#039;types&#039; (PARAM_*), helpbuttons included, etc. is all included in a function you must define in your class.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;definition()&#039;&#039; is used to define the elements in the form and &#039;&#039;&#039;this definition will be used for validating data submitted as well as for printing the form.&#039;&#039;&#039; For select and checkbox type elements only data that could have been selected will be allowed. And only data that corresponds to a form element in the definition will be accepted as submitted data.&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;definition()&#039;&#039; should include all elements that are going to be used on form, some elements may be removed or tweaked later in &#039;&#039;definition_after_data()&#039;&#039;. Please do not create conditional elements in &#039;&#039;definition()&#039;&#039;, the definition() should not directly depend on the submitted data.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_once(&amp;quot;$CFG-&amp;gt;libdir/formslib.php&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
class simplehtml_form extends moodleform {&lt;br /&gt;
&lt;br /&gt;
    function definition() {&lt;br /&gt;
        global $CFG;&lt;br /&gt;
       &lt;br /&gt;
        $mform =&amp;amp; $this-&amp;gt;_form; // Don&#039;t forget the underscore! &lt;br /&gt;
&lt;br /&gt;
        $mform-&amp;gt;addElement()... // Add elements to your form&lt;br /&gt;
            ...&lt;br /&gt;
    }                           // Close the function&lt;br /&gt;
}                               // Close the class&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use Fieldsets to group Form Elements==&lt;br /&gt;
&lt;br /&gt;
You use code like this to open a fieldset with a &#039;&#039;legend&#039;&#039;. &amp;lt;br /&amp;gt;&lt;br /&gt;
(&#039;&#039;&#039;Note&#039;&#039;&#039;: Some themes turn off legends on admin setting pages by using CSS: &amp;lt;nowiki&amp;gt;#adminsettings legend {display:none;}&amp;lt;/nowiki&amp;gt;.)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;header&#039;, &#039;nameforyourheaderelement&#039;, get_string(&#039;titleforlegened&#039;, &#039;modulename&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can&#039;t yet nest these visible fieldsets unfortunately. But in fact groups of elements are wrapped in invisible fieldsets.&lt;br /&gt;
&lt;br /&gt;
You close a fieldset with moodle_form&#039;s closeHeaderBefore method. You tell closeHeaderBefore the element before you wish to end the fieldset. A fieldset is automatically closed if you open a new one. You need to use this code only if you want to close a fieldset and the subsequent form elements are not to be enclosed by a visible fieldset (they are still enclosed with an invisibe one with no legend) :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;closeHeaderBefore(&#039;buttonar&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==addElement==&lt;br /&gt;
&lt;br /&gt;
Use the addElement method to add an element to a form. The first few arguments are always the same. The first param is the type of the element to add. The second is the elementname to use which is normally the html name of the element in the form. The third is often the text for the label for the element.&lt;br /&gt;
&lt;br /&gt;
Some examples are below :&lt;br /&gt;
=== button ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;button&#039;, &#039;intro&#039;, get_string(&amp;quot;buttonlabel&amp;quot;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A button element. If you want a submit or cancel button see &#039;submit&#039; element.&lt;br /&gt;
&lt;br /&gt;
=== checkbox ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;checkbox&#039;, &#039;ratingtime&#039;, get_string(&#039;ratingtime&#039;, &#039;forum&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a simple checkbox. The third parameter for this element is the label to display on the left side of the form. You can also supply a string as a fourth parameter to specify a label that will appear on the right of the element. Checkboxes and radio buttons can be grouped and have individual labels on their right.&lt;br /&gt;
&lt;br /&gt;
You can have a 5th parameter $attributes, as on other elements.&lt;br /&gt;
&lt;br /&gt;
==== advcheckbox ====&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;advcheckbox&#039;, &#039;ratingtime&#039;, get_string(&#039;ratingtime&#039;, &#039;forum&#039;), &#039;Label displayed after checkbox&#039;, array(&#039;group&#039; =&amp;gt; 1), array(0, 1));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similar to the checkbox above, but with a couple of important improvements:&lt;br /&gt;
&lt;br /&gt;
# The 5th parameter is a normal $attributes array, normally used to set HTML attributes for the &amp;lt;input&amp;gt; element. However, a special value of &#039;group&#039; can be given, which will add a class name to the element, and enable its grouping for a [[Development:lib/formslib.php_add_checkbox_controller|checkbox controller]]&lt;br /&gt;
#The 6th parameter is an array of values that will be associated with the checked/unchecked state of the checkbox. With a normal checkbox you cannot choose that value, and in fact an unchecked checkbox will not even be sent with the form data.&lt;br /&gt;
&lt;br /&gt;
=== choosecoursefile ===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;choosecoursefile&#039;, &#039;mediafile&#039;, get_string(&#039;mediafile&#039;, &#039;lesson&#039;), array(&#039;courseid&#039;=&amp;gt;$COURSE-&amp;gt;id));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Choose a file from the course files area. The fourth option is a list of options for the element. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
array(&#039;courseid&#039; =&amp;gt;null,  //if it is null (default then use global $COURSE&lt;br /&gt;
      &#039;height&#039;   =&amp;gt;500,   // height of the popup window&lt;br /&gt;
      &#039;width&#039;    =&amp;gt;750,   // width of the popup window&lt;br /&gt;
      &#039;options&#039;  =&amp;gt;&#039;none&#039;); //options string for the pop up window &lt;br /&gt;
                          //eg. &#039;menubar=0,location=0,scrollbars,resizable&#039;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also pass an optional 5th parameter of attributes, as for other elements. The most useful way of using that is something like &lt;br /&gt;
&amp;lt;code php&amp;gt;array(&#039;maxlength&#039; =&amp;gt; 255, &#039;size&#039; =&amp;gt; 48)&amp;lt;/code&amp;gt;&lt;br /&gt;
to control the maxlength / size of the text box (note size will default to 48 if not specified)&lt;br /&gt;
&lt;br /&gt;
Finally, as this element is a group containing two elements (button + value), you can add validation rules by using the &#039;&#039;&#039;addGroupRule()&#039;&#039;&#039; method in this (complex) way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;$mform-&amp;gt;addGroupRule(&#039;elementname&#039;, array(&#039;value&#039; =&amp;gt; array(array(list, of, rule, params, but, fieldname))));&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where: &#039;&#039;&#039;&amp;quot;elementname&amp;quot;&#039;&#039;&#039; is the name of the choosecoursefile group element, &#039;&#039;&#039;&amp;quot;value&amp;quot;&#039;&#039;&#039; is the name of the text field within the group and the &#039;&#039;&#039;&amp;quot;list, of, addrule, params, but, fieldname&amp;quot;&#039;&#039;&#039; is exactly that, the list of fields in the normal addRule() function but ommiting the first one, the fieldname.&lt;br /&gt;
&lt;br /&gt;
For example, the [http://cvs.moodle.org/moodle/mod/resource/type/file/resource.class.php?view=markup file/url resource type], uses one &amp;quot;choosecoursefile&amp;quot; element, and it controls the maximum length of the field (255) with this use of addGroupRule():&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;$mform-&amp;gt;addGroupRule(&#039;reference&#039;, array(&#039;value&#039; =&amp;gt; array(array(get_string(&#039;maximumchars&#039;, &#039;&#039;, 255), &#039;maxlength&#039;, 255, &#039;client&#039;))));&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== date_selector ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;date_selector&#039;, &#039;assesstimefinish&#039;, get_string(&#039;to&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a date selector. You can select a Day, Month and Year using a group of select boxes. The fourth param here is an array of options. The defaults for the options are :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
array(&lt;br /&gt;
    &#039;startyear&#039; =&amp;gt; 1970, &lt;br /&gt;
    &#039;stopyear&#039;  =&amp;gt; 2020,&lt;br /&gt;
    &#039;timezone&#039;  =&amp;gt; 99, &lt;br /&gt;
    &#039;applydst&#039;  =&amp;gt; true, &lt;br /&gt;
    &#039;optional&#039;  =&amp;gt; false&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can override these defaults by supplying an array as fourth param with one or more keys with a value to override the default. You can supply a fifth param of attributes here as well.&lt;br /&gt;
&lt;br /&gt;
=== date_time_selector ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;date_time_selector&#039;, &#039;assesstimestart&#039;, get_string(&#039;from&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a group of select boxes to select a date (Day Month and Year) and time (Hour and Minute). When submitted, submitted data is processed and a timestamp is passed to $form-&amp;gt;get_data(); the fourth param here is an array of options. The defaults for the options are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
array(&lt;br /&gt;
    &#039;startyear&#039; =&amp;gt; 1970, &lt;br /&gt;
    &#039;stopyear&#039;  =&amp;gt; 2020,&lt;br /&gt;
    &#039;timezone&#039;  =&amp;gt; 99, &lt;br /&gt;
    &#039;applydst&#039;  =&amp;gt; true, &lt;br /&gt;
    &#039;step&#039;      =&amp;gt; 5&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can override these defaults by supplying an array as fourth param with one or more keys with a value to override the default. You can supply a fifth param of attributes here as well.&lt;br /&gt;
&lt;br /&gt;
===duration===&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;duration&#039;, &#039;timelimit&#039;, get_string(&#039;timelimit&#039;, &#039;quiz&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
This field type lets the user input an interval of time. It comprises a text field, where you can type a number, and a dropdown for selecting a unit (days, hours, minutes or seconds). When submitted the value is converted to a number of seconds.&lt;br /&gt;
&lt;br /&gt;
You can add a fourth parameter to give options. At the moment the only option supported is here is an array of options. The defaults for the options is:&lt;br /&gt;
&amp;lt;code php&amp;gt;array(&#039;optional&#039; =&amp;gt; true)&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can also pass an optional 5th parameter of attributes, as for other elements. The most useful way of using that is something like &lt;br /&gt;
&amp;lt;code php&amp;gt;array(&#039;size&#039; =&amp;gt; 5)&amp;lt;/code&amp;gt;&lt;br /&gt;
to control the size of the text box.&lt;br /&gt;
&lt;br /&gt;
=== file ===&lt;br /&gt;
&lt;br /&gt;
File upload input box with browse button. In the form definition type&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;file&#039;, &#039;attachment&#039;, get_string(&#039;attachment&#039;, &#039;forum&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
after form submission and validation use&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if ($data = $mform-&amp;gt;get_data()) {&lt;br /&gt;
      ...&lt;br /&gt;
    $mform-&amp;gt;save_files($destination_directory);&lt;br /&gt;
      ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need advanced settings such as required file, different max upload size or name of uploaded file&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$this-&amp;gt;set_upload_manager(new upload_manager(&#039;attachment&#039;, true, false, $COURSE, false, 0, true, true, false));&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;file&#039;, &#039;attachment&#039;, get_string(&#039;attachment&#039;, &#039;forum&#039;));&lt;br /&gt;
            $mform-&amp;gt;addRule(&#039;attachment&#039;, null, &#039;required&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if ($data = $mform-&amp;gt;get_data()) {&lt;br /&gt;
      ...&lt;br /&gt;
    $mform-&amp;gt;save_files($destination_directory);&lt;br /&gt;
    $newfilename = $mform-&amp;gt;get_new_filename();&lt;br /&gt;
      ...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When porting old code it is also possible to use the upload manager directly for processing of uploaded files.&lt;br /&gt;
&lt;br /&gt;
Please note that if using set_upload_manager() it must be before addElement(&#039;file&#039;,..).&lt;br /&gt;
&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
File uploading was rewritten in 2.0. Please see inline docs for now. This page will be updated when the new API stabilises.&lt;br /&gt;
&lt;br /&gt;
===filepicker===&lt;br /&gt;
{{Moodle 2.0}}&lt;br /&gt;
General replacement of &#039;&#039;file&#039;&#039; element.&lt;br /&gt;
&lt;br /&gt;
=== hidden ===&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;hidden&#039;, &#039;reply&#039;, &#039;yes&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A hidden element. Set the element name (in this case &#039;&#039;&#039;reply&#039;&#039;&#039;) to the stated value (in this case &#039;&#039;&#039;yes&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
=== html ===&lt;br /&gt;
You can add arbitrary HTML to your Moodle form:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;html&#039;, &#039;&amp;lt;div class=&amp;quot;qheader&amp;quot;&amp;gt;&#039;);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See [http://moodle.org/mod/forum/discuss.php?d=126935 &amp;quot;Question: Can I put a moodleform inside a table td?&amp;quot;] for a concrete example.&lt;br /&gt;
&lt;br /&gt;
=== htmleditor &amp;amp; format ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;htmleditor&#039;, &#039;text&#039;, get_string(&#039;choicetext&#039;, &#039;choice&#039;));&lt;br /&gt;
$mform-&amp;gt;setType(&#039;text&#039;, PARAM_RAW);&lt;br /&gt;
$mform-&amp;gt;addRule(&#039;text&#039;, null, &#039;required&#039;, null, &#039;client&#039;);&lt;br /&gt;
&lt;br /&gt;
$mform-&amp;gt;addElement(&#039;format&#039;, &#039;format&#039;, get_string(&#039;format&#039;));&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You can supply a fourth param to htmleditor of an array of options :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
&lt;br /&gt;
array(&lt;br /&gt;
    &#039;canUseHtmlEditor&#039;=&amp;gt;&#039;detect&#039;,&lt;br /&gt;
    &#039;rows&#039;  =&amp;gt; 10, &lt;br /&gt;
    &#039;cols&#039;  =&amp;gt; 65, &lt;br /&gt;
    &#039;width&#039; =&amp;gt; 0,&lt;br /&gt;
    &#039;height&#039;=&amp;gt; 0, &lt;br /&gt;
    &#039;course&#039;=&amp;gt; 0,&lt;br /&gt;
);&lt;br /&gt;
//options same as print_textarea params&lt;br /&gt;
//use rows and cols options to control htmleditor size.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===modgrade===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;modgrade&#039;, &#039;scale&#039;, get_string(&#039;grade&#039;), false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This is a custom element for selecting a grade for any activity module. The fourth argument is whether to include an option for no grade which has a value 0. This select box does include scales. The default is true, include no grade option.&lt;br /&gt;
&lt;br /&gt;
A helpbutton is automatically added.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===password===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         $mform-&amp;gt;addElement(&#039;password&#039;, &#039;password&#039;, get_string(&#039;label&#039;), $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A password element. Fourth param is an array or string of attributes.&lt;br /&gt;
&lt;br /&gt;
===passwordunmask===&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         $mform-&amp;gt;addElement(&#039;passwordunmask&#039;, &#039;password&#039;, get_string(&#039;label&#039;), $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A password element with option to show the password in plaintext. Fourth param is an array or string of attributes.&lt;br /&gt;
&lt;br /&gt;
=== radio ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$radioarray=array();&lt;br /&gt;
$radioarray[] = &amp;amp;MoodleQuickForm::createElement(&#039;radio&#039;, &#039;yesno&#039;, &#039;&#039;, get_string(&#039;yes&#039;), 1, $attributes);&lt;br /&gt;
$radioarray[] = &amp;amp;MoodleQuickForm::createElement(&#039;radio&#039;, &#039;yesno&#039;, &#039;&#039;, get_string(&#039;no&#039;), 0, $attributes);&lt;br /&gt;
$mform-&amp;gt;addGroup($radioarray, &#039;radioar&#039;, &#039;&#039;, array(&#039; &#039;), false);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Second param names the radio button and should be the same for each button in the group in order to toggle correctly. Third param would be the label for the form element but is generally ignored as this element will always be in a group which has it&#039;s own label. Fourth param is a string, a label to be displayed on the right of the element. The fifth is the value for this radio button. $attributes can be a string or an array of attributes.&lt;br /&gt;
&lt;br /&gt;
It is possible to add help to individual radio buttons but this requires a custom template to be defined for the group elements. See MDL-15571.&lt;br /&gt;
&lt;br /&gt;
==== setDefault ====&lt;br /&gt;
&lt;br /&gt;
To set the default for a radio button group as above use the following :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$mform-&amp;gt;setDefault(&#039;yesno&#039;, 0);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This would make the default &#039;no&#039;.&lt;br /&gt;
&lt;br /&gt;
===select===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;select&#039;, &#039;type&#039;, get_string(&#039;forumtype&#039;, &#039;forum&#039;), $FORUM_TYPES, $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The fourth param for this element is an array of options for the select box. The keys are the values for the option and the value of the array is the text for the option. The fifth param $attributes is optional, see text element for description of attributes param.&lt;br /&gt;
&lt;br /&gt;
It is also possible to create a select with certain options disabled, using [http://stackoverflow.com/questions/2138089/how-can-i-use-quickform-to-add-disabled-select-options/2150275#2150275 this technique].&lt;br /&gt;
&lt;br /&gt;
====multi-select====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $select = &amp;amp;$mform-&amp;gt;addElement(&#039;select&#039;, &#039;colors&#039;, get_string(&#039;colors&#039;), array(&#039;red&#039;, &#039;blue&#039;, &#039;green&#039;), $attributes);&lt;br /&gt;
        $select-&amp;gt;setMultiple(true);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===selectyesno===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;selectyesno&#039;, &#039;maxbytes&#039;, get_string(&#039;maxattachmentsize&#039;, &#039;forum&#039;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you want a yes / no select box this one automatically translates itself and has value 1 for yes and 0 for no.&lt;br /&gt;
&lt;br /&gt;
===static===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
         $mform-&amp;gt;addElement(&#039;static&#039;, &#039;description&#039;, get_string(&#039;description&#039;, &#039;exercise&#039;),&lt;br /&gt;
                  get_string(&#039;descriptionofexercise&#039;, &#039;exercise&#039;, $COURSE-&amp;gt;students));&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is a static element. It should be used with care it is used to display a static piece of text with a label. The third param is the label and the fourth is the static text itself.&lt;br /&gt;
&lt;br /&gt;
===submit, reset and cancel===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        //normally you use add_action_buttons instead of this code&lt;br /&gt;
        $buttonarray=array();&lt;br /&gt;
        $buttonarray[] = &amp;amp;$mform-&amp;gt;createElement(&#039;submit&#039;, &#039;submitbutton&#039;, get_string(&#039;savechanges&#039;));&lt;br /&gt;
        $buttonarray[] = &amp;amp;$mform-&amp;gt;createElement(&#039;reset&#039;, &#039;resetbutton&#039;, get_string(&#039;revert&#039;));&lt;br /&gt;
        $buttonarray[] = &amp;amp;$mform-&amp;gt;createElement(&#039;cancel&#039;);&lt;br /&gt;
        $mform-&amp;gt;addGroup($buttonarray, &#039;buttonar&#039;, &#039;&#039;, array(&#039; &#039;), false);&lt;br /&gt;
        $mform-&amp;gt;closeHeaderBefore(&#039;buttonar&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A &#039;Submit&#039; type element is a submit type form element which will submit the form. A &#039;Reset&#039; will not submit the form but will reset any changes the user has made to form contents. A &#039;Cancel&#039; element cancels form submission. You need to have a branch in your code before you check for get_data() to check if submission has been cancelled with is_cancelled(); See the example on the usage page.&lt;br /&gt;
&lt;br /&gt;
You should name your submit and reset buttons &#039;submitbutton&#039; and &#039;resetbutton&#039; or something similar (not &#039;submit&#039; and &#039;reset&#039;). This avoids problems in JavaScript of collisions between form element names and names of JavaScript methods of the form object.&lt;br /&gt;
&lt;br /&gt;
====add_action_buttons($cancel = true, $submitlabel=null);====&lt;br /&gt;
&lt;br /&gt;
You will normally use this helper function which is a method of moodleform to add all the &#039;action&#039; buttons to the end of your form. A boolean parameter allow you to specify whether to include a cancel button and specify the label for your submit button (pass the result of get_string). Default for the submit button label is get_string(&#039;savechanges&#039;).&lt;br /&gt;
&lt;br /&gt;
===text===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;text&#039;, &#039;name&#039;, get_string(&#039;forumname&#039;, &#039;forum&#039;), $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
For a simple text element. Your fourth parameter here can be a string or array of attributes for the text element. The following are equivalent :&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $attributes=&#039;size=&amp;quot;20&amp;quot;&#039;;&lt;br /&gt;
        $attributes=array(&#039;size&#039;=&amp;gt;&#039;20&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
Generally you are encouraged to use CSS instead of using attributes for styling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A format element can be used as a format select box. It will be non-selectable if you&#039;re using an html editor.&lt;br /&gt;
&lt;br /&gt;
The third param for this element is $useHtmlEditor and it defaults to null in which case an html editor is used if the browser and user profile support it.&lt;br /&gt;
&lt;br /&gt;
===textarea===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;textarea&#039;, &#039;introduction&#039;, get_string(&amp;quot;introtext&amp;quot;, &amp;quot;survey&amp;quot;), &#039;wrap=&amp;quot;virtual&amp;quot; rows=&amp;quot;20&amp;quot; cols=&amp;quot;50&amp;quot;&#039;);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A textarea element. If you want an htmleditor use htmleditor element. Fourth element here is a string or array of attributes.&lt;br /&gt;
&lt;br /&gt;
===recaptcha===&lt;br /&gt;
{{Moodle 1.9}}&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;recaptcha&#039;, &#039;recaptcha_field_name&#039;, $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use this recaptcha element to reduce the spam risk in your forms. Third element here is a string or array of attributes. Take care to get an API key from http://recaptcha.net/api/getkey before using this element.&lt;br /&gt;
&lt;br /&gt;
To check whether recaptcha is enabled at site level use:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if (!empty($CFG-&amp;gt;recaptchapublickey) &amp;amp;&amp;amp; !empty($CFG-&amp;gt;recaptchaprivatekey)) {&lt;br /&gt;
    //recaptcha is enabled&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===tags===&lt;br /&gt;
&lt;br /&gt;
Moodle 2.0+ only. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;addElement(&#039;tags&#039;, &#039;field_name&#039;, $lable, $options, $attributes);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Used for editing a list of tags, for example on a blog post.&lt;br /&gt;
&lt;br /&gt;
There is only one option available, &#039;display&#039;, which should be set to one of the contstants MoodleQuickForm_tags::ONLYOFFICIAL, NOOFFICIAL or DEFAULTUI. This controls whether the official tags are listed for easy selection, or a text area where arbitrary tags may be typed, or both. The default is both.&lt;br /&gt;
&lt;br /&gt;
The value should be set/returned as an array of tags.&lt;br /&gt;
&lt;br /&gt;
==addGroup==&lt;br /&gt;
&lt;br /&gt;
A &#039;group&#039; in formslib is just a group of elements that will have a label and will be included on one line. &lt;br /&gt;
&lt;br /&gt;
For example typical code to include a submit and cancel button on the same line : &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $buttonarray=array();&lt;br /&gt;
        $buttonarray[] =&amp;amp; $mform-&amp;gt;createElement(&#039;submit&#039;, &#039;submitbutton&#039;, get_string(&#039;savechanges&#039;));&lt;br /&gt;
        $buttonarray[] =&amp;amp; $mform-&amp;gt;createElement(&#039;submit&#039;, &#039;cancel&#039;, get_string(&#039;cancel&#039;));&lt;br /&gt;
        $mform-&amp;gt;addGroup($buttonarray, &#039;buttonar&#039;, &#039;&#039;, array(&#039; &#039;), false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You use the same arguments for createElement as you do for addElement. Any label for the element in the third argument is normally ignored (but not in the case of the submit buttons above where the third argument is not for a label but is the text for the button).&lt;br /&gt;
&lt;br /&gt;
Here&#039;s a bad example (don&#039;t do this for real, use the &#039;optional&#039; =&amp;gt; true option of the date element): putting a date_selector (which is itself a group of elements) and a checkbox on the same line, note that you can disable every element in the group using the group name &#039;availablefromgroup&#039; but it doesn&#039;t disable the controlling element the &#039;availablefromenabled&#039; checkbox:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $availablefromgroup=array();&lt;br /&gt;
	$availablefromgroup[] =&amp;amp; $mform-&amp;gt;createElement(&#039;date_selector&#039;, &#039;availablefrom&#039;, &#039;&#039;);&lt;br /&gt;
	$availablefromgroup[] =&amp;amp; $mform-&amp;gt;createElement(&#039;checkbox&#039;, &#039;availablefromenabled&#039;, &#039;&#039;, get_string(&#039;enable&#039;));&lt;br /&gt;
        $mform-&amp;gt;addGroup($availablefromgroup, &#039;availablefromgroup&#039;, get_string(&#039;availablefromdate&#039;, &#039;data&#039;), &#039;&amp;amp;nbsp;&#039;, false);&lt;br /&gt;
        $mform-&amp;gt;disabledIf(&#039;availablefromgroup&#039;, &#039;availablefromenabled&#039;);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==addRule==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addRule(&#039;elementname&#039;, get_string(&#039;error&#039;), &#039;rule type&#039;, &#039;extraruledata&#039;, &#039;server&#039;(default), false, false);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first param(element) is an element name and second(message) is the error message that will be displayed to the user.&lt;br /&gt;
The third parameter(type) is the type of rule. The fourth param(format) is used for extra data needed with some rules such as minlength and regex. The fifth parameter(validation) validates input data on server or client side, if validation is done on client side then it will be checked on the server side as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * @param    string     $element       Form element name&lt;br /&gt;
 * @param    string     $message       Message to display for invalid data&lt;br /&gt;
 * @param    string     $type          Rule type, use getRegisteredRules() to get types&lt;br /&gt;
 * @param    string     $format        (optional)Required for extra rule data&lt;br /&gt;
 * @param    string     $validation    (optional)Where to perform validation: &amp;quot;server&amp;quot;, &amp;quot;client&amp;quot;&lt;br /&gt;
 * @param    boolean    $reset         Client-side validation: reset the form element to its original value if there is an error?&lt;br /&gt;
 * @param    boolean    $force         Force the rule to be applied, even if the target form element does not exist&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Common Rule Types&#039;&#039;&#039;&lt;br /&gt;
* required &lt;br /&gt;
* maxlength&lt;br /&gt;
* minlength&lt;br /&gt;
* rangelength&lt;br /&gt;
* email&lt;br /&gt;
* regex&lt;br /&gt;
* lettersonly&lt;br /&gt;
* alphanumeric&lt;br /&gt;
* numeric&lt;br /&gt;
* nopunctuation&lt;br /&gt;
* nonzero&lt;br /&gt;
* callback&lt;br /&gt;
* compare&lt;br /&gt;
&lt;br /&gt;
==setHelpButton==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
            $mform-&amp;gt;setHelpButton(&#039;lessondefault&#039;, array(&#039;lessondefault&#039;, get_string(&#039;lessondefault&#039;, &#039;lesson&#039;), &#039;lesson&#039;));&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
First param is an elementname and the second param is an array of params that are passed to helpbutton in weblib.php. Params are :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 * @param string $page  The keyword that defines a help page&lt;br /&gt;
 * @param string $title The title of links, rollover tips, alt tags etc&lt;br /&gt;
 *           &#039;Help with&#039; (or the language equivalent) will be prefixed and &#039;...&#039; will be stripped.&lt;br /&gt;
 * @param string $module Which module is the page defined in&lt;br /&gt;
 * @param mixed $image Use a help image for the link?  (true/false/&amp;quot;both&amp;quot;)&lt;br /&gt;
 * @param boolean $linktext If true, display the title next to the help icon.&lt;br /&gt;
 * @param string $text If defined then this text is used in the page, and&lt;br /&gt;
 *           the $page variable is ignored.&lt;br /&gt;
 * @param boolean $return If true then the output is returned as a string, if false it is printed to the current page.&lt;br /&gt;
 * @param string $imagetext The full text for the helpbutton icon. If empty use default help.gif&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
Make sure you don&#039;t set boolean $return to false. &lt;br /&gt;
&lt;br /&gt;
You need to do use this method after addElement();&lt;br /&gt;
&lt;br /&gt;
==setDefault==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
        $mform-&amp;gt;addElement(&#039;select&#039;, &#039;grade&#039;, get_string(&#039;gradeforsubmission&#039;, &#039;exercise&#039;), $grades);&lt;br /&gt;
        $mform-&amp;gt;setHelpButton(&#039;grade&#039;, array(&#039;grade&#039;, get_string(&#039;gradeforsubmission&#039;, &#039;exercise&#039;), &#039;exercise&#039;));&lt;br /&gt;
        $mform-&amp;gt;setDefault(&#039;grade&#039;, 100);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Set the default of the form value with setDefault($elementname, $value); where elementname is the elementname whose default you want to set and $value is the default to set. We set the defaults for the form in definition(). This default is what is used if no data is loaded into the form with set_data(); eg. on display of the form for an &#039;add&#039; rather than &#039;update&#039; function.&lt;br /&gt;
&lt;br /&gt;
==disabledIf==&lt;br /&gt;
&lt;br /&gt;
For any element or groups of element in a form you can conditionally disable the group or individual element depending on conditions.&lt;br /&gt;
&lt;br /&gt;
You can use $mform-&amp;gt;disabledIf($elementName, $dependentOn, $condition = &#039;notchecked&#039;, $value=null)&lt;br /&gt;
&lt;br /&gt;
* elementname can be a group. If you specify a group all elements in the group will be disabled (if dependentOn is in elementname group that is ignored and not disabled). These are the element names you&#039;ve used as the second argument in addElement or addGroup.&lt;br /&gt;
* dependentOn is the actual name of the element as it will appear in html. This can be different to the name used in addGroup particularly but also addElement where you&#039;re adding a complex element like a date_selector. Check the html of your page. You typically make the depedentOn a checkbox or select box.&lt;br /&gt;
* $condition will be &#039;notchecked&#039;, &#039;checked&#039;, &#039;noitemselected&#039;, &#039;eq&#039; or, if it is anything else, we test for &#039;neq&#039;.&lt;br /&gt;
** If $condition is &#039;eq&#039; or &#039;neq&#039; then we check the value of the dependentOn field and check for equality (==) or nonequality (!=) in js&lt;br /&gt;
** If $condition is &#039;checked&#039; or &#039;notchecked&#039; then we check to see if a checkbox is checked or not.&lt;br /&gt;
** If $condition is &#039;noitemselected&#039; then we check to see whether nothing is selected in a dropdown list.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
 // Disable my control unless a checkbox is checked.&lt;br /&gt;
 $mform-&amp;gt;disabledIf(&#039;mycontrol&#039;, &#039;somecheckbox&#039;);&lt;br /&gt;
 &lt;br /&gt;
 // Disable my control if a checkbox &#039;&#039;&#039;is&#039;&#039;&#039; checked.&lt;br /&gt;
 $mform-&amp;gt;disabledIf(&#039;mycontrol&#039;, &#039;somecheckbox&#039;, &#039;checked&#039;);&lt;br /&gt;
 &lt;br /&gt;
 // Disable my control unless a dropdown has value 42.&lt;br /&gt;
 $mform-&amp;gt;disabledIf(&#039;mycontrol&#039;, &#039;someselect&#039;, &#039;eq&#039;, 42);&lt;br /&gt;
&lt;br /&gt;
The possible choices here are in the function lockoptionsall in lib/javascript-static.js.&lt;br /&gt;
&lt;br /&gt;
==setType==&lt;br /&gt;
&lt;br /&gt;
PARAM_* types are used to specify how a submitted variable should be cleaned. These should be used for get parameters such as id, course etc. which are used to load a page and also with setType(); method. Every form element should have a type specified except select, radio box and checkbox elements, these elements do a good job of cleaning themselves (only specified options are allowed as user input).&lt;br /&gt;
&lt;br /&gt;
===Most Commonly Used PARAM_* Types===&lt;br /&gt;
&lt;br /&gt;
These are the most commonly used PARAM_* types and their proper uses. More types can be seen in moodlelib.php starting around line 100.&lt;br /&gt;
&lt;br /&gt;
* PARAM_CLEAN is deprecated and you should try to use a more specific type.&lt;br /&gt;
* PARAM_TEXT should be used for cleaning data that is expected to be plain text. It will strip all html tags. But will still let tags for multilang support through.&lt;br /&gt;
* PARAM_NOTAGS should be used for cleaning data that is expected to be plain text. It will strip *all* html type tags. It will still *not* let tags for multilang support through. This should be used for instance for email addresses where no multilang support is appropriate.&lt;br /&gt;
* PARAM_RAW means no cleaning whatsoever, it is used mostly for data from the html editor. Data from the editor is later cleaned before display using format_text() function. PARAM_RAW can also be used for data that is validated by some other way or printed by p() or s().&lt;br /&gt;
* PARAM_INT should be used for integers.&lt;br /&gt;
* PARAM_ACTION is an alias of PARAM_ALPHA and is used for hidden fields specifying form actions.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://www.midnighthax.com/quickform.php PEAR HTML QuickForm Getting Started Guide] by Keith Edmunds of Midnighthax.com&lt;br /&gt;
* [http://pear.php.net/manual/en/package.html.html-quickform.php PEAR::HTML_QuickForm manual]&lt;br /&gt;
&lt;br /&gt;
[[Category:Formslib]]&lt;br /&gt;
&lt;br /&gt;
If you have problems creating php forms you may get them with form builder http://phpforms.net/tutorial/html-basics/form-builder.html&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
	<entry>
		<id>https://docs.moodle.org/21/en/index.php?title=How_to_check_your_database_for_corruption&amp;diff=69243</id>
		<title>How to check your database for corruption</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/21/en/index.php?title=How_to_check_your_database_for_corruption&amp;diff=69243"/>
		<updated>2010-03-03T08:56:51Z</updated>

		<summary type="html">&lt;p&gt;Marxjohnson: Removed flippant comment about MySQL not being a &amp;quot;proper&amp;quot; database. This isn&amp;#039;t useful to someone looking for help with database corruption.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Database corruption usually occurs as a result of a hardware (especially disk-based) failure, or when a disk becomes full. Typical symptoms are failure on login, with this message displayed:&lt;br /&gt;
&lt;br /&gt;
 Session Replace: Table &#039;./moodle/mdl_sessions2&#039; is marked as crashed and should be repaired&lt;br /&gt;
&lt;br /&gt;
This problem mostly seems to affect MySQL.&lt;br /&gt;
&lt;br /&gt;
==MySQL==&lt;br /&gt;
&lt;br /&gt;
The problem can be repaired using the mysqlcheck command (the command you type is in bold and we assume the database name is &#039;moodle&#039; and its type is MySQL):&lt;br /&gt;
&lt;br /&gt;
 #&#039;&#039;&#039;mysqlcheck -u moodleuser -p --auto-repair moodle&#039;&#039;&#039;&lt;br /&gt;
 Enter password:&lt;br /&gt;
 moodle.adodb_logsql                      OK&lt;br /&gt;
 moodle.mdl_assignment                    OK&lt;br /&gt;
 moodle.mdl_assignment_submissions        OK&lt;br /&gt;
 ...&lt;br /&gt;
 moodle.mdl_log&lt;br /&gt;
 error    : Table &#039;./moodle/mdl_log&#039; is marked as crashed and should be repaired&lt;br /&gt;
 ...&lt;br /&gt;
 moodle.mdl_sessions2&lt;br /&gt;
 error    : Table &#039;./moodle/mdl_sessions2&#039; is marked as crashed and should be repaired&lt;br /&gt;
 &lt;br /&gt;
 Repairing tables&lt;br /&gt;
 moodle_18_latest.mdl_log                           OK&lt;br /&gt;
 moodle_18_latest.mdl_sessions2                     OK&lt;br /&gt;
&lt;br /&gt;
Your mysql database server must be running when executing the mysqlcheck command. If there are problems with the tables, the auto-repair option will fix them as shown above. Note that the repair process can take a long time to complete. Re-run the command again to double-check that all is OK. &lt;br /&gt;
&lt;br /&gt;
Individual Moodle tables may be repaired using MySQL Admin/PHPMyAdmin as follows:&lt;br /&gt;
# In the databases section, select the Moodle database.&lt;br /&gt;
# Click the SQL tab, then in the &amp;quot;Run SQL query/queries on database moodle&amp;quot; field type &amp;lt;code&amp;gt;REPAIR TABLE mdl_tablename&amp;lt;/code&amp;gt;&lt;br /&gt;
# Click the Go button.&lt;br /&gt;
For example, to repair the Moodle log tables, type &amp;lt;code&amp;gt;REPAIR TABLE mdl_log&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Other databases==&lt;br /&gt;
&lt;br /&gt;
As I said above, this issue normally only occurs with MySQL.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
*[http://moodle.org/mod/forum/discuss.php?d=58208#279638 Forum discussion] on a moodle database optimization script&lt;br /&gt;
*[[Performance#MySQL_performance | Performance Documentation]] on database repair and optimization&lt;br /&gt;
*[http://www.databasejournal.com/features/mysql/article.php/10897_3300511_2 Database Journal article on repairing database corruption in MySQL]&lt;br /&gt;
&lt;br /&gt;
[[Category:Administrator]]&lt;br /&gt;
[[de:Wie man die Konsistenz der Moodle-Datenbank prüft]]&lt;/div&gt;</summary>
		<author><name>Marxjohnson</name></author>
	</entry>
</feed>