| 1 | efrain | 1 | ---
 | 
        
           |  |  | 2 | layout: docs
 | 
        
           |  |  | 3 | title: "Form elements"
 | 
        
           |  |  | 4 | description: "Custom form elements for Moodle"
 | 
        
           |  |  | 5 | date: 2020-01-14T16:32:24+01:00
 | 
        
           |  |  | 6 | draft: false
 | 
        
           |  |  | 7 | weight: 30
 | 
        
           |  |  | 8 | tags:
 | 
        
           |  |  | 9 | - In development
 | 
        
           |  |  | 10 | ---
 | 
        
           |  |  | 11 |   | 
        
           |  |  | 12 | ## How to use moodle forms
 | 
        
           |  |  | 13 |   | 
        
           |  |  | 14 | Forms are constructed using lib/formslib.php. Using the addElement methods in php a set of different form element types can be added to a form. For more info visit the [Moodledocs](https://moodledev.io/docs/apis/subsystems/form) page for forms
 | 
        
           |  |  | 15 |   | 
        
           |  |  | 16 | {{< php >}}
 | 
        
           |  |  | 17 |     $mform->addElement('button', 'intro', get_string("buttonlabel"));
 | 
        
           |  |  | 18 | {{< / php >}}
 | 
        
           |  |  | 19 |   | 
        
           |  |  | 20 | Form elements are styled using Moodle templates which are rendered through PHP. Themes can override these templates.
 | 
        
           |  |  | 21 |   | 
        
           |  |  | 22 | Form elements are styled using the .form-control class, see the [Bootstrap](/bootstrap-4.3/forms/input-group/) docs for more info.
 | 
        
           |  |  | 23 |   | 
        
           |  |  | 24 | ## Example form elements
 | 
        
           |  |  | 25 |   | 
        
           |  |  | 26 | The example form below is showing an iframe with an actual Moodle form. Use the toggle options to display the different states for the form.
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 |   | 
        
           |  |  | 29 | <iframe src="../../../../examples/formfields.php" style="overflow:hidden;height:4000px;width:100%;border:0" title="Moodle form fields"></iframe>
 |