Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
|
Elements embedded in question text editing form definition. More...
Public Member Functions | |
_process_submission ($method) | |
Internal method. | |
_validate_files (&$files) | |
Internal method. | |
add_action_buttons ($cancel=true, $submitlabel=null) | |
Use this method to a cancel and submit button to the end of your form. | |
add_checkbox_controller ($groupid, $text=null, $attributes=null, $originalValue=0) | |
Adds a link/button that controls the checked state of a group of checkboxes. | |
data_preprocessing ($question) | |
Perform an preprocessing needed on the data passed to set_data() before it is used to initialise the form. | |
definition_after_data () | |
Tweak the form with values provided by custom fields in use. | |
display () | |
Print html form. | |
focus ($name=NULL) | |
To autofocus on first form element or first element with error. | |
get_data () | |
Return submitted data if properly submitted or returns NULL if validation fails or if there is no submitted data. | |
get_file_content ($elname) | |
Get content of uploaded file. | |
get_maximum_choice_group_number () | |
Return how many different groups of choices there should be. | |
get_new_filename ($elname=null) | |
Returns name of uploaded file. | |
get_submitted_data () | |
Return submitted data without validation or NULL if there is no submitted data. | |
init_javascript_enhancement ($element, $enhancement, array $options=array(), array $strings=null) | |
Adds an initialisation call for a standard JavaScript enhancement. | |
is_cancelled () | |
Return true if a cancel button has been pressed resulting in the form being submitted. | |
is_submitted () | |
Check that form was submitted. | |
is_validated () | |
Check that form data is valid. | |
moodleform ($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true) | |
Old syntax of class constructor. | |
no_submit_button_pressed () | |
Checks if button pressed is not for submitting the form. | |
optional_param ($name, $default, $type) | |
Checks if a parameter was passed in the previous form submission. | |
qtype () | |
Override this in the subclass to question type name. | |
render () | |
Renders the html form (same as display, but returns the result). | |
repeat_elements ($elementobjs, $repeats, $options, $repeathiddenname, $addfieldsname, $addfieldsno=5, $addstring=null, $addbuttoninside=false, $deletebuttonname='') | |
Method to add a repeating group of elements to a form. | |
repeat_elements_fix_clone ($i, $elementclone, &$namecloned) | |
Helper used by repeat_elements(). | |
save_file ($elname, $pathname, $override=false) | |
Save file to standard filesystem. | |
save_files ($destination) | |
Save verified uploaded files into directory. | |
save_stored_file ($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/', $newfilename=null, $overwrite=false, $newuserid=null) | |
Save file to local filesystem pool. | |
save_temp_file ($elname) | |
Returns a temporary file, do not forget to delete after not needed any more. | |
set_data ($question) | |
Load in existing data as form defaults. | |
set_display_vertical () | |
Set display mode for the form when labels take full width of the form and above the elements even on big screens. | |
set_initial_dirty_state ($state=false) | |
Set the initial 'dirty' state of the form. | |
validate_defined_fields ($validateonnosubmit=false) | |
Validate the form. | |
validation ($data, $files) | |
Dummy stub method - override if you needed to perform some extra validation. | |
Static Public Member Functions | |
static | get_js_module () |
Returns a JS module definition for the mforms JS. | |
static | mock_ajax_submit ($simulatedsubmitteddata, $simulatedsubmittedfiles=array(), $method='post', $formidentifier=null) |
Used by tests to simulate submitted form data submission via AJAX. | |
static | mock_generate_submit_keys ($data=[]) |
Used by tests to generate valid submit keys for moodle forms that are submitted with ajax data. | |
static | mock_submit ($simulatedsubmitteddata, $simulatedsubmittedfiles=array(), $method='post', $formidentifier=null) |
Used by tests to simulate submitted form data submission from the user. | |
Protected Member Functions | |
_get_post_params () | |
Internal method - should not be used anywhere. | |
add_combined_feedback_fields ($withshownumpartscorrect=false) | |
add_hidden_fields () | |
Add all the hidden form fields used by question/question.php. | |
add_interactive_settings ($withclearwrong=false, $withshownumpartscorrect=false) | |
add_per_answer_fields (&$mform, $label, $gradeoptions, $minoptions=QUESTION_NUMANS_START, $addoptions=QUESTION_NUMANS_ADD) | |
Add a set of form fields, obtained from get_per_answer_fields, to the form, one for each existing answer, with some blanks for some new ones. | |
add_tag_fields ($mform) | |
Add the tag and course tag fields to the mform. | |
after_definition () | |
After definition hook. | |
can_preview () | |
Is the question being edited in a state where it can be previewed? | |
choice_group ($mform) | |
Creates an array with elements for a choice group. | |
data_preprocessing_answers ($question, $withanswerfiles=false) | |
Perform the necessary preprocessing for the fields added by add_per_answer_fields(). | |
data_preprocessing_choice ($question, $answer, $key) | |
data_preprocessing_combined_feedback ($question, $withshownumcorrect=false) | |
Perform the necessary preprocessing for the fields added by add_combined_feedback_fields(). | |
data_preprocessing_extra_answer_field ($answer, $field) | |
Perfmorm preprocessing for particular extra answer field. | |
data_preprocessing_extra_answer_fields ($question, $extraanswerfields) | |
Perform the necessary preprocessing for the extra answer fields. | |
data_preprocessing_hints ($question, $withclearwrong=false, $withshownumpartscorrect=false) | |
Perform the necessary preprocessing for the hint fields. | |
definition () | |
Build the form definition. | |
definition_answer_choice (&$mform) | |
Defines form elements for answer choices. | |
definition_inner ($mform) | |
definition_inner adds all specific fields to the form. | |
extra_slot_validation (array $slots, array $choices) | |
Finds more errors in question slots. | |
get_array_value_by_keys (array $array, array $keys) | |
Returns an element of multi-dimensional array given the list of keys. | |
get_default_value (string $name, $default) | |
Return default value for a given form element either from user_preferences table or $default. | |
get_draft_files ($elname) | |
Get draft files of a form element This is a protected method which will be used only inside moodleforms. | |
get_form_identifier () | |
It should returns unique identifier for the form. | |
get_hint_fields ($withclearwrong=false, $withshownumpartscorrect=false) | |
Create the form elements required by one hint. | |
get_illegal_tag_error ($text) | |
Vaidate some input to make sure it does not contain any tags other than $this->allowedhtmltags. | |
get_more_choices_string () | |
Language string to use for 'Add {no} more {whatever we call answers}'. | |
get_non_collabsible_editor_options () | |
Returns an array of editor options with collapsed options turned off. | |
get_per_answer_fields ($mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption) | |
Get the list of form elements to repeat, one for each answer. | |
repeated_options () | |
Returns an array for form repeat options. | |
validate_draft_files () | |
Internal method. | |
Protected Attributes | |
array | $_ajaxformdata |
submitted form data when using mforms with ajax | |
mixed | $_customdata |
globals workaround | |
object | $_definition_finalized = false |
definition_after_data executed flag | |
MoodleQuickForm | $_form |
quickform object definition | |
string | $_formname |
name of the form | |
bool null | $_validated = null |
stores the validation result of this form or null if not yet validated | |
array | $allowedhtmltags |
of HTML tags allowed in choices / drag boxes. | |
$category | |
$categorycontext | |
$contexts | |
object | $customfieldhandler |
instance of custom field | |
bool | $customfieldpluginenabled = true |
custom field plugin enabled or disabled | |
object | $question |
Question object with options and answers already loaded by get_question_options Be careful how you use this it is needed sometimes to set up the structure of the form in definition_inner but data is always loaded into the form with set_data. | |
Elements embedded in question text editing form definition.
|
protectedinherited |
Add a set of form fields, obtained from get_per_answer_fields, to the form, one for each existing answer, with some blanks for some new ones.
object | $mform | the form being built. |
$label | the label to use for each option. | |
$gradeoptions | the possible grades for each answer. | |
$minoptions | the minimum number of answer blanks to display. Default QUESTION_NUMANS_START. | |
$addoptions | the number of answer blanks to add. Default QUESTION_NUMANS_ADD. |
|
protectedinherited |
Add the tag and course tag fields to the mform.
If the form is being built in a course context then add the field for course tags.
If the question category doesn't belong to a course context or we aren't editing in a course context then add the tags element to allow tags to be added to the question category context.
object | $mform | The form being built |
|
protectedinherited |
Is the question being edited in a state where it can be previewed?
bool | whether to show the preview link. |
Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, and qtype_calculatedsimple_edit_form.
|
protected |
Creates an array with elements for a choice group.
object | $mform | The Moodle form we are working with |
int | $maxgroup | The number of max group generate element select. |
array | Array for form elements |
Reimplemented in qtype_ddwtos_edit_form.
qtype_gapselect_edit_form_base::data_preprocessing | ( | $question | ) |
Perform an preprocessing needed on the data passed to set_data() before it is used to initialise the form.
object | $question | the data being passed to the form. |
object\$question | the modified data. |
Reimplemented from question_edit_form.
|
protectedinherited |
Perform the necessary preprocessing for the fields added by add_per_answer_fields().
object | $question | the data being passed to the form. |
object\$question | the modified data. |
Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, and qtype_numerical_edit_form.
|
protectedinherited |
Perform the necessary preprocessing for the fields added by add_combined_feedback_fields().
object | $question | the data being passed to the form. |
object\$question | the modified data. |
|
protectedinherited |
Perfmorm preprocessing for particular extra answer field.
Questions with non-trivial DB - form element relationship will want to override this.
object | $answer | an answer object to get extra field from. |
string | $field | extra answer field name. |
field | value to be set to the form. |
|
protectedinherited |
Perform the necessary preprocessing for the extra answer fields.
Questions that do something not trivial when editing extra answer fields will want to override this.
object | $question | the data being passed to the form. |
array | $extraanswerfields | extra answer fields (without table name). |
object\$question | the modified data. |
|
protectedinherited |
Perform the necessary preprocessing for the hint fields.
object | $question | the data being passed to the form. |
object\$question | the modified data. |
Reimplemented in qtype_ddmarker_edit_form.
|
protectedinherited |
Build the form definition.
This adds all the form fields that the default question type supports. If your question type does not support all these fields, then you can override this method and remove the ones you don't want with $mform->removeElement().
Reimplemented from moodleform.
Reimplemented in qtype_random_edit_form.
|
inherited |
Tweak the form with values provided by custom fields in use.
Reimplemented from moodleform.
|
protected |
Defines form elements for answer choices.
object | $mform | The Moodle form object being built |
|
protected |
definition_inner adds all specific fields to the form.
object | $mform | (the form being built). |
Reimplemented from question_edit_form.
|
protected |
Finds more errors in question slots.
array | $slots | The question text |
array | $choices | Question choices |
string|null | Error message or false if no errors |
Reimplemented in qtype_ddwtos_edit_form.
|
protectedinherited |
Return default value for a given form element either from user_preferences table or $default.
To make use of user_preferences in your qtype default settings, you need to replace $mform->setDefault({elementname}, {defaultvalue}); in edit_{qtypename}_form.php with $mform->setDefault({elementname}, $this->get_default_value({elementname}, {defaultvalue}));
string | $name | the name of the form field. |
mixed | $default | default value. |
string|null | default value for a given form element. |
|
protectedinherited |
Create the form elements required by one hint.
string | $withclearwrong | whether this quesiton type uses the 'Clear wrong' option on hints. |
string | $withshownumpartscorrect | whether this quesiton type uses the 'Show num parts correct' option on hints. |
array | form field elements for one hint. |
Reimplemented in qtype_ddmarker_edit_form, and qtype_multichoice_edit_form.
|
protected |
Vaidate some input to make sure it does not contain any tags other than $this->allowedhtmltags.
string | $text | the input to validate. |
string | any validation errors. |
qtype_gapselect_edit_form_base::get_maximum_choice_group_number | ( | ) |
Return how many different groups of choices there should be.
int | the maximum group number. |
Reimplemented in qtype_gapselect_edit_form.
|
protectedinherited |
Language string to use for 'Add {no} more {whatever we call answers}'.
Reimplemented in qtype_match_edit_form, qtype_numerical_edit_form, and qtype_shortanswer_edit_form.
|
protectedinherited |
Returns an array of editor options with collapsed options turned off.
array |
|
protectedinherited |
Get the list of form elements to repeat, one for each answer.
object | $mform | the form being built. |
$label | the label to use for each option. | |
$gradeoptions | the possible grades for each answer. | |
$repeatedoptions | reference to array of repeated options to fill | |
$answersoption | reference to return the name of $question->options field holding an array of answers |
array | of form fields. |
Reimplemented in qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, qtype_match_edit_form, qtype_multichoice_edit_form, and qtype_numerical_edit_form.
qtype_gapselect_edit_form_base::qtype | ( | ) |
Override this in the subclass to question type name.
the | question type name, should be the same as the name() method in the question type class. |
Reimplemented from question_edit_form.
Reimplemented in qtype_ddwtos_edit_form, and qtype_gapselect_edit_form.
|
protected |
Returns an array for form repeat options.
array | Array of repeate options |
|
inherited |
Load in existing data as form defaults.
Usually new entry defaults are stored directly in form definition (new entry form); this function is used to load in data where values already exist and data is being edited (edit entry form).
note: $slashed param removed
stdClass | array | $default_values | object or array of default values |
Reimplemented from moodleform.
Reimplemented in qtype_missingtype_edit_form, qtype_multianswer_edit_form, and qtype_random_edit_form.
qtype_gapselect_edit_form_base::validation | ( | $data, | |
$files ) |
Dummy stub method - override if you needed to perform some extra validation.
If there are errors return array of errors ("fieldname"=>"error message"), otherwise true if ok.
Server side rules do not work for uploaded files, implement serverside rules here if needed.
array | $data | array of ("fieldname"=>value) of submitted data |
array | $files | array of uploaded files "element_name"=>tmp_file_path |
array | of "element_name"=>"error_description" if there are errors, or an empty array if everything is OK (true allowed for backwards compatibility too). |
Reimplemented from question_edit_form.
|
protected |
of HTML tags allowed in choices / drag boxes.