Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
moodleform Class Reference

Wrapper that separates quickforms syntax from moodle code. More...

Inheritance diagram for moodleform:
admin_settings_search_form admin_uploadpicture_form admin_uploaduser_form1 admin_uploaduser_form2 alignment_form assign_override_form assignfeedback_file_batch_upload_files_form assignfeedback_file_import_zip_form assignfeedback_file_upload_zip_form assignfeedback_offline_import_grades_form assignfeedback_offline_upload_grades_form atto_managefiles_manage_form autogroup_form backup_files_edit_form badges_preferences_form base_moodleform block_edit_form blog_edit_external_form blog_edit_form blog_preferences_form book_chapter_edit_form booktool_importhtml_form cache_definition_mappings_form cache_definition_sharing_form cache_lock_form cache_mode_mappings_form cachestore_addinstance_form category_form cohort_edit_form cohort_upload_form contentbank_files_form core\form\persistent core\hub\site_registration_form core_admin\form\purge_caches core_admin\form\testoutgoingmailconf_form core_auth\form\verify_age_location_form core_backup\output\copy_form core_badges\form\backpack core_badges\form\badge core_badges\form\collections core_badges\form\external_backpack core_badges\form\message core_calendar\local\event\forms\create core_calendar\local\event\forms\managesubscriptions core_calendar_export_form core_completion_edit_base_form core_contentbank\form\edit_content core_course_deletecategory_form core_course_editcategory_form core_customfield\field_config_form core_h5p\form\uploadlibraries_form core_question\form\tags core_role_permission_allow_form core_role_permission_prohibit_form core_role_preset_form core_search\output\form\search core_user\course_form core_user\form\calendar_form core_user\form\defaulthomepage_form course_completion_form course_edit_form course_request_form course_reset_form course_restore_form course_settings_form coursefiles_edit_form coursetags_form data_existing_preset_form data_export_form data_import_preset_zip_form data_save_preset_form database_export_form database_transfer_form edit_calculation_form edit_category_form edit_criteria_form edit_grade_form edit_item_form edit_letter_form edit_outcome_form edit_outcomeitem_form edit_relatedbadge_form edit_scale_form editsection_form endorsement_form enrol_bulk_enrolment_change_form enrol_guest_enrol_form enrol_instance_edit_form enrol_manual_enrol_users_form enrol_self_empty_form enrol_self_enrol_form enrol_user_enrolment_form enrol_users_addmember_form enrol_users_assign_form enrol_users_filter_form essay_grading_form event_form external_service_authorised_user_settings_form external_service_form external_service_functions_form feedback_edit_create_template_form feedback_edit_use_template_form feedback_import_form feedback_item_form field_form filter_local_settings_form forumreport_summary\form\dates_filter_form grade_export_form grade_import_form grade_import_form grade_import_mapping_form gradeimport_direct_import_form gradeimport_direct_mapping_form grader_report_preferences_form gradereport_history\filter_form grading_search_template_form gradingform_guide_editguide gradingform_rubric_editrubric group_form grouping_form groups_import_form import_outcomes_form key_form key_form lesson_add_page_form_base lesson_display_answer_form_essay lesson_display_answer_form_matching lesson_display_answer_form_multichoice_multianswer lesson_display_answer_form_multichoice_singleanswer lesson_display_answer_form_numerical lesson_display_answer_form_shortanswer lesson_display_answer_form_truefalse lesson_import_form lesson_override_form lesson_page_without_answers login_change_password_form login_forgot_password_form login_forgot_password_form login_set_password_form login_signup_form mnet_profile_form mnet_review_host_form mnet_services_form mnet_simple_host_form mod_assign_batch_set_allocatedmarker_form mod_assign_batch_set_marking_workflow_state_form mod_assign_confirm_submission_form mod_assign_extension_form mod_assign_grade_form mod_assign_grading_batch_operations_form mod_assign_grading_options_form mod_assign_quick_grading_form mod_assign_submission_form mod_data_export_form mod_data_import_form mod_feedback_complete_form mod_feedback_course_map_form mod_feedback_course_select_form mod_feedback_use_templ_form mod_folder_edit_form mod_forum\form\export_form mod_forum_post_form mod_forum_prune_form mod_glossary_entry_form mod_glossary_import_form mod_lti_edit_types_form mod_lti_register_types_form mod_quiz\form\randomquestion_form mod_quiz_attempts_report_form mod_quiz_preflight_check_form mod_scorm_report_interactions_settings mod_scorm_report_objectives_settings mod_scorm_report_settings mod_wiki_comments_form mod_wiki_create_form mod_wiki_edit_form mod_wiki_filesedit_form moodleform_mod note_edit_form portfolio_admin_form portfolio_export_form portfolio_instance_select portfolio_user_form preview_options_form profiling_import_form question_category_edit_form question_export_form question_import_form question_move_form question_wizard_form quiz_add_random_form quiz_grading_settings_form quiz_override_form quiz_statistics_settings_form recent_form reject_request_form report_configlog\form\search report_eventlist_filter_form report_outline\filter_form repository_instance_form repository_type_form steps_definitions_form switchrole_form tag_edit_form tool_analytics\output\form\edit_model tool_analytics\output\form\import_model tool_capability_settings_form tool_cohortroles\form\assign_role_cohort tool_customlang_filter_form tool_filetypes_form tool_generator_make_course_form tool_generator_make_testplan_form tool_httpsreplace\form tool_installaddon_installfromzip_form tool_licensemanager\form\edit_license tool_lp\form\template_cohorts tool_lp\form\template_plans tool_lpimportcsv\form\export tool_lpimportcsv\form\import tool_lpimportcsv\form\import_confirm tool_lpmigrate\form\migrate_framework tool_messageinbound_edit_handler_form tool_monitor\rule_form tool_policy\form\accept_policy tool_policy\form\policydoc tool_replace_form tool_task_edit_scheduled_task_form tool_uploadcourse_base_form tool_usertours\local\forms\editstep tool_usertours\local\forms\edittour tool_usertours\local\forms\importtour user_active_filter_form user_add_filter_form user_bulk_action_form user_bulk_cohortadd_form user_bulk_form user_edit_editor_form user_edit_form user_edit_forum_form user_edit_language_form user_editadvanced_form user_files_form user_message_form web_service_token_form webservice_test_client_base_form webservice_test_client_form workshop_assessment_form workshop_edit_strategy_form workshop_evaluation_settings_form workshop_feedbackauthor_form workshop_feedbackreviewer_form workshop_random_allocator_form workshop_submission_form

Public Member Functions

 __construct ($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
 The constructor function calls the abstract function definition() and it will then process and clean and attempt to validate incoming data. More...
 
 _process_submission ($method)
 Internal method. More...
 
 _validate_files (&$files)
 Internal method. More...
 
 add_action_buttons ($cancel=true, $submitlabel=null)
 Use this method to a cancel and submit button to the end of your form. More...
 
 add_checkbox_controller ($groupid, $text=null, $attributes=null, $originalValue=0)
 Adds a link/button that controls the checked state of a group of checkboxes. More...
 
 definition_after_data ()
 Dummy stub method - override if you need to setup the form depending on current values. More...
 
 display ()
 Print html form. More...
 
 focus ($name=NULL)
 To autofocus on first form element or first element with error. More...
 
 get_data ()
 Return submitted data if properly submitted or returns NULL if validation fails or if there is no submitted data. More...
 
 get_file_content ($elname)
 Get content of uploaded file. More...
 
 get_new_filename ($elname=null)
 Returns name of uploaded file. More...
 
 get_submitted_data ()
 Return submitted data without validation or NULL if there is no submitted data. More...
 
 init_javascript_enhancement ($element, $enhancement, array $options=array(), array $strings=null)
 Adds an initialisation call for a standard JavaScript enhancement. More...
 
 is_cancelled ()
 Return true if a cancel button has been pressed resulting in the form being submitted. More...
 
 is_submitted ()
 Check that form was submitted. More...
 
 is_validated ()
 Check that form data is valid. More...
 
 moodleform ($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true)
 Old syntax of class constructor. More...
 
 no_submit_button_pressed ()
 Checks if button pressed is not for submitting the form. More...
 
 optional_param ($name, $default, $type)
 Checks if a parameter was passed in the previous form submission. More...
 
 render ()
 Renders the html form (same as display, but returns the result). More...
 
 repeat_elements ($elementobjs, $repeats, $options, $repeathiddenname, $addfieldsname, $addfieldsno=5, $addstring=null, $addbuttoninside=false)
 Method to add a repeating group of elements to a form. More...
 
 repeat_elements_fix_clone ($i, $elementclone, &$namecloned)
 Helper used by repeat_elements(). More...
 
 save_file ($elname, $pathname, $override=false)
 Save file to standard filesystem. More...
 
 save_files ($destination)
 Save verified uploaded files into directory. More...
 
 save_stored_file ($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/', $newfilename=null, $overwrite=false, $newuserid=null)
 Save file to local filesystem pool. More...
 
 save_temp_file ($elname)
 Returns a temporary file, do not forget to delete after not needed any more. More...
 
 set_data ($default_values)
 Load in existing data as form defaults. More...
 
 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. More...
 
 set_initial_dirty_state ($state=false)
 Set the initial 'dirty' state of the form. More...
 
 validate_defined_fields ($validateonnosubmit=false)
 Validate the form. More...
 
 validation ($data, $files)
 Dummy stub method - override if you needed to perform some extra validation. More...
 

Static Public Member Functions

static get_js_module ()
 Returns a JS module definition for the mforms JS. More...
 
static mock_generate_submit_keys ($data=[])
 Used by tests to generate valid submit keys for moodle forms that are submitted with ajax data. More...
 
static mock_submit ($simulatedsubmitteddata, $simulatedsubmittedfiles=array(), $method='post', $formidentifier=null)
 Used by tests to simulate submitted form data submission from the user. More...
 

Protected Member Functions

 _get_post_params ()
 Internal method - should not be used anywhere. More...
 
 after_definition ()
 After definition hook. More...
 
 definition ()
 Form definition. More...
 
 get_draft_files ($elname)
 Get draft files of a form element This is a protected method which will be used only inside moodleforms. More...
 
 get_form_identifier ()
 It should returns unique identifier for the form. More...
 
 validate_draft_files ()
 Internal method. More...
 

Protected Attributes

array $_ajaxformdata
 submitted form data when using mforms with ajax
 
array $_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
 

Detailed Description

Wrapper that separates quickforms syntax from moodle code.

Moodle specific wrapper that separates quickforms syntax from moodle code. You won't directly use this class you should write a class definition which extends this class or a more specific subclass such a moodleform_mod for each form you want to display and/or process with formslib.

You will write your own definition() method which performs the form set up.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Todo:
MDL-19380 rethink the file scanning

Constructor & Destructor Documentation

◆ __construct()

moodleform::__construct (   $action = null,
  $customdata = null,
  $method = 'post',
  $target = '',
  $attributes = null,
  $editable = true,
  $ajaxformdata = null 
)

The constructor function calls the abstract function definition() and it will then process and clean and attempt to validate incoming data.

It will call your custom validate method to validate data and will also check any rules you have specified in definition using addRule

The name of the form (id attribute of the form) is automatically generated depending on the name you gave the class extending moodleform. You should call your class something like

Parameters
mixed$actionthe action attribute for the form. If empty defaults to auto detect the current url. If a moodle_url object then outputs params as hidden variables.
mixed$customdataif your form defintion method needs access to data such as $course $cm, etc. to construct the form definition then pass it in this array. You can use globals for somethings.
string$methodif you set this to anything other than 'post' then _GET and _POST will be merged and used as incoming data to the form.
string$targettarget frame for form submission. You will rarely use this. Don't use it if you don't need to as the target attribute is deprecated in xhtml strict.
mixed$attributesyou can pass a string of html attributes here or an array. Special attribute 'data-random-ids' will randomise generated elements ids. This is necessary when there are several forms on the same page. Special attribute 'data-double-submit-protection' set to 'off' will turn off double-submit protection JavaScript - this may be necessary if your form sends downloadable files in response to a submit button, and can't call core_form::util::form_download_complete();
bool$editable
array$ajaxformdataForms submitted via ajax, must pass their data here, instead of relying on _GET and _POST.

Reimplemented in core\form\persistent, and assign_override_form.

Member Function Documentation

◆ _get_post_params()

moodleform::_get_post_params ( )
protected

Internal method - should not be used anywhere.

Deprecated:
since 2.6
Return values
array::$_POST,.

◆ _process_submission()

moodleform::_process_submission (   $method)

Internal method.

Alters submitted data to be suitable for quickforms processing. Must be called when the form is fully set up.

Parameters
string$methodname of the method which alters submitted data

◆ _validate_files()

moodleform::_validate_files ( $files)

Internal method.

Validates all old-style deprecated uploaded files. The new way is to upload files via repository api.

Parameters
array$fileslist of files to be validated
Return values
bool|arraySuccess or an array of errors

◆ add_action_buttons()

moodleform::add_action_buttons (   $cancel = true,
  $submitlabel = null 
)

Use this method to a cancel and submit button to the end of your form.

Pass a param of false if you don't want a cancel button in your form. If you have a cancel button make sure you check for it being pressed using is_cancelled() and redirecting if it is true before trying to get data with get_data().

Parameters
bool$cancelwhether to show cancel button, default true
string$submitlabellabel for submit button, defaults to get_string('savechanges')

Reimplemented in tool_uploadcourse_step2_form, and core_contentbank\form\edit_content.

◆ add_checkbox_controller()

moodleform::add_checkbox_controller (   $groupid,
  $text = null,
  $attributes = null,
  $originalValue = 0 
)

Adds a link/button that controls the checked state of a group of checkboxes.

Parameters
int$groupidThe id of the group of advcheckboxes this element controls
string$textThe text of the link. Defaults to selectallornone ("select all/none")
array$attributesassociative array of HTML attributes
int$originalValueThe original general state of the checkboxes before the user first clicks this element

◆ after_definition()

moodleform::after_definition ( )
protected

After definition hook.

This is useful for intermediate classes to inject logic after the definition was provided without requiring developers to call the parent self::definition()} as it's not obvious by design. The 'intermediate' class is 'MyClass extends IntermediateClass extends moodleform'.

Classes overriding this method should always call the parent. We may not add anything specifically in this instance of the method, but intermediate classes are likely to do so, and so it is a good practice to always call the parent.

Return values
void

Reimplemented in core\form\persistent.

◆ definition()

moodleform::definition ( )
abstractprotected

Form definition.

Abstract method - always override!

Reimplemented in admin_settings_search_form, core_admin\form\purge_caches, core_admin\form\testoutgoingmailconf_form, mnet_simple_host_form, mnet_review_host_form, mnet_profile_form, mnet_services_form, core_role_permission_allow_form, core_role_permission_prohibit_form, core_role_preset_form, tool_analytics\output\form\edit_model, tool_analytics\output\form\import_model, steps_definitions_form, tool_capability_settings_form, tool_cohortroles\form\assign_role_cohort, tool_customlang_filter_form, tool_dataprivacy\form\category, tool_dataprivacy\form\context_instance, tool_dataprivacy\form\contextlevel, tool_dataprivacy\form\purpose, tool_dataprivacy_data_request_form, database_export_form, database_transfer_form, tool_filetypes_form, tool_generator_make_course_form, tool_generator_make_testplan_form, tool_httpsreplace\form, tool_installaddon_installfromzip_form, tool_licensemanager\form\edit_license, tool_lp\form\competency, tool_lp\form\competency_framework, tool_lp\form\plan, tool_lp\form\template, tool_lp\form\template_cohorts, tool_lp\form\template_plans, tool_lp\form\user_evidence, tool_lpimportcsv\form\export, tool_lpimportcsv\form\import, tool_lpimportcsv\form\import_confirm, tool_lpmigrate\form\migrate_framework, tool_messageinbound_edit_handler_form, tool_monitor\rule_form, tool_oauth2\form\endpoint, tool_oauth2\form\issuer, tool_oauth2\form\user_field_mapping, tool_policy\form\accept_policy, tool_policy\form\policydoc, profiling_import_form, tool_replace_form, tool_task_edit_scheduled_task_form, tool_uploadcourse_base_form, tool_uploadcourse_step1_form, tool_uploadcourse_step2_form, admin_uploadpicture_form, admin_uploaduser_form1, admin_uploaduser_form2, tool_usertours\local\forms\editstep, tool_usertours\local\forms\edittour, tool_usertours\local\forms\importtour, user_bulk_cohortadd_form, user_bulk_action_form, user_bulk_form, user_message_form, external_service_authorised_user_settings_form, external_service_form, external_service_functions_form, web_service_token_form, webservice_test_client_form, webservice_test_client_base_form, core_auth\form\verify_age_location_form, backup_files_edit_form, course_restore_form, base_moodleform, core_backup\output\copy_form, alignment_form, core_badges\form\backpack, core_badges\form\badge, core_badges\form\collections, core_badges\form\external_backpack, core_badges\form\message, edit_criteria_form, endorsement_form, badges_preferences_form, edit_relatedbadge_form, block_edit_form, blog_edit_form, blog_edit_external_form, blog_preferences_form, cachestore_addinstance_form, cache_definition_mappings_form, cache_definition_sharing_form, cache_mode_mappings_form, cache_lock_form, core_calendar_export_form, core_calendar\local\event\forms\create, core_calendar\local\event\forms\managesubscriptions, event_form, cohort_edit_form, cohort_upload_form, core_completion_bulkedit_form, core_completion_defaultedit_form, core_completion_edit_base_form, contenttype_h5p\form\editor, contentbank_files_form, core_course_deletecategory_form, core_course_editcategory_form, course_completion_form, course_edit_form, editsection_form, recent_form, course_request_form, reject_request_form, course_reset_form, switchrole_form, coursetags_form, core_customfield\field_config_form, enrol_bulk_enrolment_change_form, enrol_bulk_enrolment_confirm_form, enrol_user_enrolment_form, enrol_instance_edit_form, enrol_guest_enrol_form, enrol_manual_enrol_users_form, enrol_self_empty_form, enrol_self_enrol_form, enrol_users_assign_form, enrol_users_addmember_form, enrol_users_filter_form, coursefiles_edit_form, filter_local_settings_form, edit_letter_form, edit_outcome_form, import_outcomes_form, edit_scale_form, course_settings_form, edit_calculation_form, edit_category_form, edit_grade_form, edit_item_form, edit_outcomeitem_form, grade_export_form, key_form, gradingform_guide_editguide, gradingform_rubric_editrubric, grading_search_template_form, gradeimport_direct_import_form, gradeimport_direct_mapping_form, grade_import_form, grade_import_mapping_form, key_form, grade_import_form, grader_report_preferences_form, gradereport_history\filter_form, autogroup_form, group_form, grouping_form, groups_import_form, core_h5p\form\uploadlibraries_form, core\hub\site_registration_form, atto_managefiles_manage_form, portfolio_export_form, portfolio_admin_form, portfolio_user_form, portfolio_instance_select, login_change_password_form, login_forgot_password_form, login_forgot_password_form, login_set_password_form, login_signup_form, mod_assign_batch_set_allocatedmarker_form, mod_assign_batch_set_marking_workflow_state_form, mod_assign_extension_form, assignfeedback_file_batch_upload_files_form, assignfeedback_file_import_zip_form, assignfeedback_file_upload_zip_form, assignfeedback_offline_import_grades_form, assignfeedback_offline_upload_grades_form, mod_assign_grade_form, mod_assign_grading_batch_operations_form, mod_assign_grading_options_form, mod_assign_mod_form, assign_override_form, mod_assign_quick_grading_form, mod_assign_submission_form, mod_assign_confirm_submission_form, mod_assignment_mod_form, book_chapter_edit_form, mod_book_mod_form, booktool_importhtml_form, mod_chat_mod_form, mod_choice_mod_form, mod_data_export_form, mod_data_import_form, mod_data_mod_form, data_existing_preset_form, data_import_preset_zip_form, data_export_form, data_save_preset_form, mod_feedback_complete_form, mod_feedback_course_map_form, mod_feedback_course_select_form, feedback_edit_use_template_form, feedback_edit_create_template_form, feedback_import_form, feedback_captcha_form, feedback_item_form, feedback_info_form, feedback_label_form, feedback_multichoice_form, feedback_multichoicerated_form, feedback_numeric_form, feedback_textarea_form, feedback_textfield_form, mod_feedback_mod_form, mod_feedback_use_templ_form, mod_folder_edit_form, mod_folder_mod_form, mod_forum\form\export_form, mod_forum_post_form, mod_forum_prune_form, mod_forum_mod_form, forumreport_summary\form\dates_filter_form, mod_glossary_entry_form, mod_glossary_import_form, mod_glossary_mod_form, mod_h5pactivity_mod_form, mod_imscp_mod_form, mod_label_mod_form, essay_grading_form, lesson_import_form, lesson_add_page_form_base, mod_lesson_mod_form, lesson_override_form, lesson_display_answer_form_essay, lesson_display_answer_form_matching, lesson_display_answer_form_multichoice_singleanswer, lesson_display_answer_form_multichoice_multianswer, lesson_display_answer_form_numerical, lesson_display_answer_form_shortanswer, lesson_display_answer_form_truefalse, lesson_page_without_answers, mod_lti_edit_types_form, mod_lti_mod_form, mod_lti_register_types_form, mod_page_mod_form, mod_quiz_preflight_check_form, quizaccess_seb\local\form\template, quiz_add_random_form, mod_quiz\form\randomquestion_form, mod_quiz_mod_form, quiz_override_form, mod_quiz_attempts_report_form, quiz_grading_settings_form, quiz_statistics_settings_form, mod_resource_mod_form, mod_scorm_mod_form, mod_scorm_report_interactions_settings, mod_scorm_report_objectives_settings, mod_scorm_report_settings, mod_survey_mod_form, mod_url_mod_form, mod_wiki_comments_form, mod_wiki_create_form, mod_wiki_edit_form, mod_wiki_filesedit_form, mod_wiki_mod_form, workshop_random_allocator_form, workshop_scheduled_allocator_form, workshop_evaluation_settings_form, workshop_feedbackauthor_form, workshop_feedbackreviewer_form, workshop_assessment_form, workshop_edit_strategy_form, mod_workshop_mod_form, workshop_submission_form, note_edit_form, question_category_edit_form, question_export_form, question_import_form, question_move_form, preview_options_form, question_dataset_dependent_definitions_form, question_dataset_dependent_items_form, question_edit_form, qtype_random_edit_form, core_question\form\tags, report_configlog\form\search, report_eventlist_filter_form, report_outline\filter_form, repository_instance_form, repository_type_form, core_search\output\form\search, tag_edit_form, core_user\course_form, core_user\form\calendar_form, core_user\form\defaulthomepage_form, user_edit_form, user_editadvanced_form, user_edit_editor_form, user_files_form, user_add_filter_form, user_active_filter_form, user_edit_forum_form, user_edit_language_form, category_form, and field_form.

◆ definition_after_data()

moodleform::definition_after_data ( )

◆ display()

moodleform::display ( )

Print html form.

Reimplemented in base_moodleform, cohort_upload_form, and mod_feedback_complete_form.

◆ focus()

moodleform::focus (   $name = NULL)

To autofocus on first form element or first element with error.

Parameters
string$nameif this is set then the focus is forced to a field with this name
Return values
stringjavascript to select form element with first error or first element if no errors. Use this as a parameter when calling print_header

◆ get_data()

moodleform::get_data ( )

◆ get_draft_files()

moodleform::get_draft_files (   $elname)
protected

Get draft files of a form element This is a protected method which will be used only inside moodleforms.

Parameters
string$elnamename of element
Return values
array|bool|null

◆ get_file_content()

moodleform::get_file_content (   $elname)

Get content of uploaded file.

Parameters
string$elnamename of file upload element
Return values
string|boolfalse in case of failure, string if ok

◆ get_form_identifier()

moodleform::get_form_identifier ( )
protected

It should returns unique identifier for the form.

Currently it will return class name, but in case two same forms have to be rendered on same page then override function to get unique form identifier. e.g This is used on multiple self enrollments page.

Return values
stringform identifier.

Reimplemented in enrol_self_enrol_form, and mod_assign_grade_form.

◆ get_js_module()

static moodleform::get_js_module ( )
static

Returns a JS module definition for the mforms JS.

Return values
array

◆ get_new_filename()

moodleform::get_new_filename (   $elname = null)

Returns name of uploaded file.

Parameters
string$elnamefirst element if null
Return values
string|boolfalse in case of failure, string if ok

◆ get_submitted_data()

moodleform::get_submitted_data ( )

Return submitted data without validation or NULL if there is no submitted data.

note: $slashed param removed

Return values
objectsubmitted data; NULL if not submitted

Reimplemented in core\form\persistent, and lesson_add_page_form_numerical.

◆ init_javascript_enhancement()

moodleform::init_javascript_enhancement (   $element,
  $enhancement,
array  $options = array(),
array  $strings = null 
)

Adds an initialisation call for a standard JavaScript enhancement.

This function is designed to add an initialisation call for a JavaScript enhancement that should exist within javascript-static M.form.init_{enhancementname}.

Current options:

  • Selectboxes
    • smartselect: Turns a nbsp indented select box into a custom drop down control that supports multilevel and category selection. $enhancement = 'smartselect'; $options = array('selectablecategories' => true|false)
Parameters
string | element$elementform element for which Javascript needs to be initalized
string$enhancementwhich init function should be called
array$optionsoptions passed to javascript
array$stringsstrings for javascript
Deprecated:
since Moodle 3.3 MDL-57471

◆ is_cancelled()

moodleform::is_cancelled ( )

Return true if a cancel button has been pressed resulting in the form being submitted.

Return values
booltrue if a cancel button has been pressed

Reimplemented in base_moodleform.

◆ is_submitted()

moodleform::is_submitted ( )

Check that form was submitted.

Does not check validity of submitted data.

Return values
booltrue if form properly submitted

◆ is_validated()

moodleform::is_validated ( )

Check that form data is valid.

You should almost always use this, rather than validate_defined_fields

Return values
booltrue if form data valid

◆ mock_generate_submit_keys()

static moodleform::mock_generate_submit_keys (   $data = [])
static

Used by tests to generate valid submit keys for moodle forms that are submitted with ajax data.

Exceptions
moodle_exceptionIf called outside unit test environment
Parameters
array$dataExisting form data you wish to add the keys to.
Return values
array

◆ mock_submit()

static moodleform::mock_submit (   $simulatedsubmitteddata,
  $simulatedsubmittedfiles = array(),
  $method = 'post',
  $formidentifier = null 
)
static

Used by tests to simulate submitted form data submission from the user.

For form fields where no data is submitted the default for that field as set by set_data or setDefault will be passed to get_data.

This method sets $_POST or $_GET and $_FILES with the data supplied. Our unit test code empties all these global arrays after each test.

Parameters
array$simulatedsubmitteddataAn associative array of form values (same format as $_POST).
array$simulatedsubmittedfilesAn associative array of files uploaded (same format as $_FILES). Can be omitted.
string$method'post' or 'get', defaults to 'post'.
null$formidentifierthe default is to use the class name for this class but you may need to provide a different value here for some forms that are used more than once on the same page.

◆ moodleform()

moodleform::moodleform (   $action = null,
  $customdata = null,
  $method = 'post',
  $target = '',
  $attributes = null,
  $editable = true 
)

Old syntax of class constructor.

Deprecated in PHP7.

Deprecated:
since Moodle 3.1

◆ no_submit_button_pressed()

moodleform::no_submit_button_pressed ( )

Checks if button pressed is not for submitting the form.

@staticvar bool $nosubmit keeps track of no submit button

Return values
bool

◆ optional_param()

moodleform::optional_param (   $name,
  $default,
  $type 
)

Checks if a parameter was passed in the previous form submission.

Parameters
string$namethe name of the page parameter we want
mixed$defaultthe default value to return if nothing is found
string$typeexpected type of parameter
Return values
mixed

◆ render()

moodleform::render ( )

Renders the html form (same as display, but returns the result).

Note that you can only output this rendered result once per page, as it contains IDs which must be unique.

Return values
stringHTML code for the form

◆ repeat_elements()

moodleform::repeat_elements (   $elementobjs,
  $repeats,
  $options,
  $repeathiddenname,
  $addfieldsname,
  $addfieldsno = 5,
  $addstring = null,
  $addbuttoninside = false 
)

Method to add a repeating group of elements to a form.

Parameters
array$elementobjsArray of elements or groups of elements that are to be repeated
int$repeatsno of times to repeat elements initially
array$optionsa nested array. The first array key is the element name. the second array key is the type of option to set, and depend on that option, the value takes different forms. 'default' - default value to set. Can include '{no}' which is replaced by the repeat number. 'type' - PARAM_* type. 'helpbutton' - array containing the helpbutton params. 'disabledif' - array containing the disabledIf() arguments after the element name. 'rule' - array containing the addRule arguments after the element name. 'expanded' - whether this section of the form should be expanded by default. (Name be a header element.) 'advanced' - whether this element is hidden by 'Show more ...'.
string$repeathiddennamename for hidden element storing no of repeats in this form
string$addfieldsnamename for button to add more fields
int$addfieldsnohow many fields to add at a time
string$addstringname of button, {no} is replaced by no of blanks that will be added.
bool$addbuttoninsideif true, don't call closeHeaderBefore($addfieldsname). Default false.
Return values
intno of repeats of element in this page

◆ repeat_elements_fix_clone()

moodleform::repeat_elements_fix_clone (   $i,
  $elementclone,
$namecloned 
)

Helper used by repeat_elements().

Parameters
int$ithe index of this element.
HTML_QuickForm_element$elementclone
array$nameclonedarray of names

◆ save_file()

moodleform::save_file (   $elname,
  $pathname,
  $override = false 
)

Save file to standard filesystem.

Parameters
string$elnamename of element
string$pathnamefull path name of file
bool$overrideoverride file if exists
Return values
boolsuccess

◆ save_files()

moodleform::save_files (   $destination)

Save verified uploaded files into directory.

Upload process can be customised from definition()

Deprecated:
since Moodle 2.0
Todo:
MDL-31294 remove this api
See also
moodleform::save_stored_file()
moodleform::save_file()
Parameters
string$destinationpath where file should be stored
Return values
boolAlways false

◆ save_stored_file()

moodleform::save_stored_file (   $elname,
  $newcontextid,
  $newcomponent,
  $newfilearea,
  $newitemid,
  $newfilepath = '/',
  $newfilename = null,
  $overwrite = false,
  $newuserid = null 
)

Save file to local filesystem pool.

Parameters
string$elnamename of element
int$newcontextidid of context
string$newcomponentname of the component
string$newfileareaname of file area
int$newitemiditem id
string$newfilepathpath of file where it get stored
string$newfilenameuse specified filename, if not specified name of uploaded file used
bool$overwriteoverwrite file if exists
int$newuseridnew userid if required
Return values
mixedstored_file object or false if error; may throw exception if duplicate found

◆ save_temp_file()

moodleform::save_temp_file (   $elname)

Returns a temporary file, do not forget to delete after not needed any more.

Parameters
string$elnamename of the elmenet
Return values
string|booleither string or false

◆ set_data()

moodleform::set_data (   $default_values)

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

Parameters
stdClass | array$default_valuesobject or array of default values

Reimplemented in core_badges\form\badge, question_category_edit_form, tool_dataprivacy\form\purpose, tool_filetypes_form, cache_definition_sharing_form, editsection_form, moodleform_mod, block_edit_form, block_html_edit_form, lesson_add_page_form_numerical, mod_lti_mod_form, mod_quiz\form\randomquestion_form, mod_scorm_mod_form, feedback_multichoice_form, feedback_multichoicerated_form, question_dataset_dependent_items_form, question_edit_form, qtype_missingtype_edit_form, qtype_multianswer_edit_form, and qtype_random_edit_form.

◆ set_display_vertical()

moodleform::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.

Useful for forms displayed inside modals or in narrow containers

◆ set_initial_dirty_state()

moodleform::set_initial_dirty_state (   $state = false)

Set the initial 'dirty' state of the form.

Parameters
bool$state
Since
Moodle 3.7.1

◆ validate_defined_fields()

moodleform::validate_defined_fields (   $validateonnosubmit = false)

Validate the form.

You almost always want to call is_validated instead of this because it calls definition_after_data first, before validating the form, which is what you want in 99% of cases.

This is provided as a separate function for those special cases where you want the form validated before definition_after_data is called for example, to selectively add new elements depending on a no_submit_button press, but only when the form is valid when the no_submit_button is pressed,

Parameters
bool$validateonnosubmitoptional, defaults to false. The default behaviour is NOT to validate the form when a no submit button has been pressed. pass true here to override this behaviour
Return values
booltrue if form data valid

◆ validate_draft_files()

moodleform::validate_draft_files ( )
protected

Internal method.

Validates filepicker and filemanager files if they are set as required fields. Also, sets the error message if encountered one.

Return values
bool|arraywith errors

◆ validation()

moodleform::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.

Parameters
array$dataarray of ("fieldname"=>value) of submitted data
array$filesarray of uploaded files "element_name"=>tmp_file_path
Return values
arrayof "element_name"=>"error_description" if there are errors, or an empty array if everything is OK (true allowed for backwards compatibility too).

Reimplemented in core_admin\form\purge_caches, mnet_simple_host_form, mnet_review_host_form, core_role_preset_form, tool_analytics\output\form\edit_model, database_transfer_form, tool_filetypes_form, tool_generator_make_course_form, tool_generator_make_testplan_form, tool_installaddon_installfromzip_form, tool_licensemanager\form\edit_license, tool_lpmigrate\form\migrate_framework, tool_monitor\rule_form, tool_policy\form\policydoc, tool_replace_form, tool_task_edit_scheduled_task_form, tool_uploadcourse_step2_form, admin_uploaduser_form2, external_service_form, web_service_token_form, backup_confirmation_form, core_backup\output\copy_form, alignment_form, core_badges\form\backpack, core_badges\form\badge, core_badges\form\external_backpack, edit_criteria_form, endorsement_form, edit_relatedbadge_form, blog_edit_form, blog_edit_external_form, cachestore_addinstance_form, cache_definition_sharing_form, cache_lock_form, cachestore_memcached_addinstance_form, core_calendar\local\event\forms\create, core_calendar\local\event\forms\managesubscriptions, event_form, cohort_edit_form, cohort_upload_form, core_completion_bulkedit_form, core_completion_edit_base_form, contentbank_files_form, core_course_deletecategory_form, core_course_editcategory_form, course_edit_form, editsection_form, moodleform_mod, course_request_form, course_reset_form, enrol_user_enrolment_form, enrol_instance_edit_form, enrol_guest_enrol_form, enrol_manual_enrol_users_form, enrol_self_enrol_form, edit_outcome_form, edit_scale_form, edit_calculation_form, edit_category_form, edit_item_form, edit_outcomeitem_form, gradingform_guide_editguide, gradingform_rubric_editrubric, grade_import_form, grader_report_preferences_form, autogroup_form, group_form, grouping_form, core\form\persistent, core\hub\site_registration_form, portfolio_export_form, portfolio_admin_form, portfolio_user_form, login_change_password_form, login_forgot_password_form, login_set_password_form, login_signup_form, mod_assign_batch_set_marking_workflow_state_form, mod_assign_extension_form, mod_assign_grade_form, mod_assign_mod_form, assign_override_form, booktool_importhtml_form, mod_choice_mod_form, mod_data_mod_form, feedback_edit_create_template_form, mod_feedback_mod_form, mod_folder_mod_form, mod_forum_post_form, mod_forum_mod_form, mod_glossary_entry_form, mod_h5pactivity_mod_form, mod_imscp_mod_form, lesson_import_form, mod_lesson_mod_form, lesson_override_form, mod_lti_edit_types_form, mod_quiz_preflight_check_form, mod_quiz_mod_form, quiz_override_form, mod_quiz_attempts_report_form, quiz_responses_settings_form, mod_resource_mod_form, mod_scorm_mod_form, mod_url_mod_form, workshop_feedbackauthor_form, workshop_feedbackreviewer_form, workshop_edit_strategy_form, workshop_rubric_assessment_form, mod_workshop_mod_form, workshop_submission_form, question_category_edit_form, question_import_form, question_dataset_dependent_definitions_form, question_dataset_dependent_items_form, qtype_calculated_edit_form, qtype_calculatedmulti_edit_form, qtype_calculatedsimple_edit_form, qtype_ddimageortext_edit_form, qtype_ddmarker_edit_form, qtype_gapselect_edit_form_base, qtype_match_edit_form, qtype_missingtype_edit_form, qtype_multianswer_edit_form, qtype_multichoice_edit_form, qtype_numerical_edit_form, qtype_randomsamatch_edit_form, qtype_shortanswer_edit_form, repository_instance_form, repository_type_form, tag_edit_form, user_files_form, category_form, field_form, core_customfield\field_config_form, quiz_add_random_form, question_edit_form, qtype_essay_edit_form, qtype_random_edit_form, user_edit_form, and user_editadvanced_form.


The documentation for this class was generated from the following file: