David Mudrak (talk | contribs) m (Text replacement - "class="nicetable"" to "class="wikitable"") |
|||
Line 1: | Line 1: | ||
==Edit form template== | ==Edit form template== | ||
{| class=" | {| class="wikitable" | ||
|+ Form template | |+ Form template | ||
|- | |- | ||
Line 33: | Line 33: | ||
==Form data compilation for displaying== | ==Form data compilation for displaying== | ||
{| class=" | {| class="wikitable" | ||
|+ Form data compilation for display | |+ Form data compilation for display | ||
|- | |- | ||
Line 117: | Line 117: | ||
==Saving a form== | ==Saving a form== | ||
{| class=" | {| class="wikitable" | ||
|+ Form saving | |+ Form saving | ||
|- | |- | ||
Line 166: | Line 166: | ||
==New form elements== | ==New form elements== | ||
{| class=" | {| class="wikitable" | ||
|+ New form elements | |+ New form elements | ||
|- | |- | ||
Line 281: | Line 281: | ||
==Form library and helper functions== | ==Form library and helper functions== | ||
{| class=" | {| class="wikitable" | ||
|+ Library | |+ Library | ||
|- | |- |
Latest revision as of 13:25, 14 July 2021
Edit form template
Type A | Type B |
---|---|
|
Form data compilation for displaying
Type A | Type B |
---|---|
|
|
Saving a form
Type A | Type B |
---|---|
|
|
New form elements
Type A | Type B |
---|---|
|
Template for a select element
Same for both.
<label {{#hiddenLabel}}class="accesshide"Adrian Greeve/form comparison/hiddenLabel for="Template:id">
Template:label
{{#required}}{{>core/form-required}}Adrian Greeve/form comparison/required
{{#advanced}}{{>core/form-advanced}}Adrian Greeve/form comparison/advanced
</label>
{{{helpButton}}}
{{#error}}
{{{error}}}
Adrian Greeve/form comparison/error
<select name="Template:name" id="Template:id" {{#required}}requiredAdrian Greeve/form comparison/required {{#size}}size="Template:size"Adrian Greeve/form comparison/size>
{{#options}}
<option value="Template:value" {{#selected}}selectedAdrian Greeve/form comparison/selected>Template:text</option>
Adrian Greeve/form comparison/options
</select>
Form library and helper functions
Type A | Type B |
---|---|
|
|
Simple web service
class mod_lesson_external extends external_api {
public static function add_page_parameters() {
return new external_function_parameters(
array(
'lessonid' => new external_value(PARAM_INT, 'lesson module ID'),
'pageid' => new external_value(PARAM_INT, 'lesson page ID'),
'title' => new external_value(PARAM_TEXT, 'lesson page title', VALUE_OPTIONAL)
)
);
}
public static function add_page($lessonid, $pageid, $title) {
$params = self::validate_parameters(self::add_page_parameters(),
array($lessonid, $pageid, $title));
$errors = array();
if (empty($title)) {
$errors["code"] = "formvalidationfailed";
$errors["message"] = "Validation Failed";
$errors["errors"] = array('code' => 'notitlefound', 'name' => 'title', 'message' => 'Title must not be empty');
return array('status' => false, 'warnings' => $errors);
}
return array('status' => true, 'warnings' => $errors);
}
public static function add_page_returns() {
return new external_single_structure(
array(
'status' => new external_value(PARAM_BOOL, 'status: true if success'),
'warnings' => new external_warnings()
)
);
}
}