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()
)
);
}
}