From b29c9b05e678fb1ca63173a0d394e44ae68bd5d3 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 2 Aug 2011 12:17:44 +0800 Subject: [PATCH] MDL-27728 Moodleforms: Added validation for element before checking element values --- lib/formslib.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/formslib.php b/lib/formslib.php index 1787b0f2855..8c529beb6fb 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -1731,6 +1731,12 @@ var skipClientValidation = false; function qf_errorHandler(element, _qfMsg) { div = element.parentNode; + + if ((div == undefined) || (element.name == undefined)) { + //no checking can be done for undefined elements so let server handle it. + return true; + } + if (_qfMsg != \'\') { var errorSpan = document.getElementById(\'id_error_\'+element.name); if (!errorSpan) { @@ -1780,16 +1786,25 @@ function qf_errorHandler(element, _qfMsg) { $elementName); $js .= ' function validate_' . $this->_formName . '_' . $escapedElementName . '(element) { + if (undefined == element) { + //required element was not found, then let form be submitted without client side validation + return true; + } var value = \'\'; var errFlag = new Array(); var _qfGroups = {}; var _qfMsg = \'\'; var frm = element.parentNode; - while (frm && frm.nodeName.toUpperCase() != "FORM") { - frm = frm.parentNode; + if ((undefined != element.name) && (frm != undefined)) { + while (frm && frm.nodeName.toUpperCase() != "FORM") { + frm = frm.parentNode; + } + ' . join("\n", $jsArr) . ' + return qf_errorHandler(element, _qfMsg); + } else { + //element name should be defined else error msg will not be displayed. + return true; } -' . join("\n", $jsArr) . ' - return qf_errorHandler(element, _qfMsg); } '; $validateJS .= '