From d5fb9a23989169890431acc1cfd0cfe5952882c8 Mon Sep 17 00:00:00 2001 From: Dries Buytaert <dries@buytaert.net> Date: Thu, 21 Dec 2006 16:16:44 +0000 Subject: [PATCH] - Patch #104598 by ChrisKennedy: validate max length of textfields. --- includes/form.inc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/form.inc b/includes/form.inc index 28055474f4d0..4c95ce22a413 100644 --- a/includes/form.inc +++ b/includes/form.inc @@ -521,6 +521,11 @@ function _form_validate($elements, $form_id = NULL) { form_error($elements, t('!name field is required.', array('!name' => $elements['#title']))); } + // Verify that the value is not longer than #maxlength. + if (isset($elements['#maxlength']) && drupal_strlen($elements['#value']) > $elements['#maxlength']) { + form_error($elements, t('!name cannot be longer than %max characters but is currently %length characters long.', array('!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'], '%max' => $elements['#maxlength'], '%length' => drupal_strlen($elements['#value'])))); + } + // Add legal choice check if element has #options. Can be skipped, but then you must validate your own element. if (isset($elements['#options']) && isset($elements['#value']) && !isset($elements['#DANGEROUS_SKIP_CHECK'])) { if ($elements['#type'] == 'select') { -- GitLab