From f2314ad49ea834f0831b1a8d39b8bdb0f716ff34 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 24 Apr 2013 17:43:49 +0800 Subject: [PATCH] Updated the validation of the width and height for the customcert page --- edit_form.php | 10 ++++++---- lang/en/customcert.php | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/edit_form.php b/edit_form.php index e20c5ae..8a705f8 100644 --- a/edit_form.php +++ b/edit_form.php @@ -148,16 +148,18 @@ class mod_customcert_edit_form extends moodleform { foreach ($data as $key => $value) { if (strpos($key, 'width_') !== false) { $page = str_replace('width_', '', $key); + $widthid = 'width_' . $page; // Validate that the width is a valid value. - if (!isset($data['width_' . $page]) || !is_number($data['width_' . $page])) { - $errors['width_' . $page] = get_string('widthnotvalid', 'customcert'); + if ((!isset($data[$widthid])) || (!is_numeric($data[$widthid])) || ($data[$widthid] <= 0)) { + $errors[$widthid] = get_string('widthnotvalid', 'customcert'); } } if (strpos($key, 'height_') !== false) { $page = str_replace('height_', '', $key); + $heightid = 'height_' . $page; // Validate that the height is a valid value. - if (!isset($data['height_' . $page]) || !is_number($data['height_' . $page])) { - $errors['height_' . $page] = get_string('heightnotvalid', 'customcert'); + if ((!isset($data[$heightid])) || (!is_numeric($data[$heightid])) || ($data[$heightid] <= 0)) { + $errors[$heightid] = get_string('heightnotvalid', 'customcert'); } } } diff --git a/lang/en/customcert.php b/lang/en/customcert.php index 833ab26..018877d 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -46,7 +46,7 @@ $string['fontsize'] = 'Size'; $string['fontsize_help'] = 'The size of the font in points.'; $string['getcustomcert'] = 'Get your custom certificate'; $string['height'] = 'Height'; -$string['heightnotvalid'] = 'The height has to be a valid number.'; +$string['heightnotvalid'] = 'The height has to be a valid number greater than 0.'; $string['height_help'] = 'This is the height of the certificate PDF in mm. For reference an A4 piece of paper is 297mm high and a letter is 279mm high.'; $string['invalidcolour'] = 'Invalid colour chosen, please enter a valid HTML colour name, or a six-digit, or three-digit hexadecimal colour.'; $string['invalidposition'] = 'Please select a positive number for position {$a}.'; @@ -71,5 +71,5 @@ $string['summaryofissue'] = 'Summary of issue'; $string['uploadimage'] = 'Upload image'; $string['viewcustomcertissues'] = 'View {$a} issued custom certificates'; $string['width'] = 'Width'; -$string['widthnotvalid'] = 'The width has to be a valid number.'; +$string['widthnotvalid'] = 'The width has to be a valid number greater than 0.'; $string['width_help'] = 'This is the width of the certificate PDF in mm. For reference an A4 piece of paper is 210mm wide and a letter is 216mm wide.';