Commit 80375b14 authored by Jono Mingard's avatar Jono Mingard

Added top-level form errors to complement specific ones (Bug #1262483)

Pieforms now adds a global error message if there are any validation errors
in a form, in addition to the messages beside each element. This is
modified from the existing jserrormessage

Change-Id: I15b9f4238ec3e5b1e6cb7fcff0514855565f0364
Signed-off-by: default avatarJono Mingard <jonom@catalyst.net.nz>
parent 32edab99
......@@ -103,6 +103,9 @@ $compositeform = pieform($cform);
$javascript = <<<EOF
function editcomposite_callback(form, data) {
editcomposite_filebrowser.callback(form, data);
if (data.error) {
formError(form, data);
}
};
EOF;
......
......@@ -509,6 +509,7 @@ function auth_setup () {
// specify login data immediately
require_once('pieforms/pieform.php');
$form = new Pieform(auth_get_login_form());
$SESSION->loginform = $form;
if ($USER->is_logged_in()) {
return;
}
......@@ -1871,10 +1872,14 @@ function auth_remove_old_session_files() {
* auth_get_login_form, but keep that in mind when making changes.}}
*/
function auth_generate_login_form() {
global $SESSION;
require_once('pieforms/pieform.php');
if (!get_config('installed')) {
return;
}
else if ($SESSION->loginform) {
return get_login_form_js($SESSION->loginform->build());
}
$elements = auth_get_login_form_elements();
$loginform = get_login_form_js(pieform(array(
'name' => 'login',
......
......@@ -201,7 +201,7 @@ class Session {
*/
public function render_messages($placement = 'messages') {
global $THEME;
$result = '<div id="' . $placement . '">';
$result = '<div id="' . $placement . '" role="alert" aria-live="assertive">';
if (isset($_SESSION['messages'])) {
foreach ($_SESSION['messages'] as $key => $data) {
if ($data['placement'] == $placement) {
......
......@@ -1872,6 +1872,7 @@ function pieform_configure() {
'presubmitcallback' => 'formStartProcessing',
'postsubmitcallback' => 'formStopProcessing',
'jserrormessage' => get_string('errorprocessingform'),
'errormessage' => get_string('errorprocessingform'),
'configdirs' => get_config('libroot') . 'form/',
'helpcallback' => 'pieform_get_help',
'elements' => array(
......
......@@ -563,6 +563,10 @@ class Pieform {/*{{{*/
$message = $this->get_property('jserrormessage');
$this->json_reply(PIEFORM_ERR, array('message' => $message));
}
else {
global $SESSION;
$SESSION->add_error_msg($this->get_property('errormessage'));
}
}
}/*}}}*/
......@@ -971,6 +975,7 @@ EOF;
if ($subelement['name'] == $name) {
$subelement['error'] = $message;
$subelement['isescaped'] = ($isescaped) ? true : false;
$this->data['haserror'] = true;
return;
}
}
......@@ -979,6 +984,7 @@ EOF;
if ($key == $name) {
$element['error'] = $message;
$element['isescaped'] = ($isescaped) ? true : false;
$this->data['haserror'] = true;
return;
}
}
......@@ -1564,6 +1570,10 @@ EOF;
// you choose.
'jserrormessage' => '',
// A message to add to the list of global error messages if form submission
// fails (and the form isn't a jsform)
'errormessage' => '',
// Whether this form can be cancelled, regardless of the presence of
// 'cancel' buttons or form inputs mischeviously named as to behave
// like cancel buttons
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment