Updated the validation of the width and height for the customcert page

This commit is contained in:
Mark Nelson 2013-04-24 17:43:49 +08:00
parent 7781024377
commit f2314ad49e
2 changed files with 8 additions and 6 deletions

View file

@ -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');
}
}
}

View file

@ -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.';