Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
02716408
Commit
02716408
authored
Nov 17, 2006
by
Nigel McNie
Committed by
Nigel McNie
Nov 17, 2006
Browse files
Updated for new function signature - form parameter is first, so that
$form->i18n can be called for multilanguage error messages.
parent
8f39bf2a
Changes
5
Hide whitespace changes
Inline
Side-by-side
htdocs/lib/form/rules/email.php
View file @
02716408
...
...
@@ -32,13 +32,14 @@ defined('INTERNAL') || die();
* Currently, the check is [anything]@[anything]. Someone is welcome to write
* something better, this was made just for testing.
*
* @param string $address The e-mail address to check
* @param Form $form The form the rule is being applied to
* @param string $value The e-mail address to check
* @return string The error message, if there is something wrong with
* the address.
*/
function
form_rule_email
(
$address
)
{
if
(
!
preg_match
(
'/^(.*)@(.*)\.(.*)$/'
,
$
address
))
{
return
get_string
(
'E-mail address is invalid
'
);
function
form_rule_email
(
Form
$form
,
$value
)
{
if
(
!
preg_match
(
'/^(.*)@(.*)\.(.*)$/'
,
$
value
))
{
return
$form
->
i18n
(
'email
'
);
}
}
...
...
htdocs/lib/form/rules/maxlength.php
View file @
02716408
...
...
@@ -29,14 +29,15 @@ defined('INTERNAL') || die();
/**
* Checks whether the given value is longer than the allowed length.
*
* @param Form $form The form the rule is being applied to
* @param string $value The value to check
* @param array $element The element to check
* @param int $maxlength The length to check for
* @return string The error message, if the value is invalid.
*/
function
form_rule_maxlength
(
$value
,
$element
,
$maxlength
)
{
function
form_rule_maxlength
(
Form
$form
,
$value
,
$element
,
$maxlength
)
{
if
(
strlen
(
$value
)
>
$maxlength
)
{
return
get_string
(
'This field can only be '
.
$maxlength
.
' characters long'
);
return
sprintf
(
$form
->
i18n
(
'maxlength'
),
$maxlength
);
}
}
...
...
htdocs/lib/form/rules/minlength.php
View file @
02716408
...
...
@@ -29,14 +29,15 @@ defined('INTERNAL') || die();
/**
* Checks whether the given value is shorter than the allowed length.
*
* @param Form $form The form the rule is being applied to
* @param string $value The value to check
* @param array $element The element to check
* @param int $minlength The length to check for
* @return string The error message, if the value is invalid.
*/
function
form_rule_minlength
(
$value
,
$element
,
$minlength
)
{
function
form_rule_minlength
(
Form
$form
,
$value
,
$element
,
$minlength
)
{
if
(
strlen
(
$value
)
<
$minlength
)
{
return
get_string
(
'This field must be at least '
.
$minlength
.
' characters long'
);
return
sprintf
(
$form
->
i18n
(
'minlength'
),
$minlength
);
}
}
...
...
htdocs/lib/form/rules/required.php
View file @
02716408
...
...
@@ -29,37 +29,24 @@ defined('INTERNAL') || die();
/**
* Checks whether the field has been specified.
*
* @param Form $form The form the rule is being applied to
* @param string $field The field to check
* @param array $element The element to check
* @return string The error message, if the value is invalid.
*/
function
form_rule_required
(
$field
,
$element
)
{
function
form_rule_required
(
Form
$form
,
$value
,
$element
)
{
// The array test is for using the "required" rule on file elements
$function
=
'form_is_empty_'
.
$element
[
'type'
];
if
(
function_exists
(
$function
))
{
if
(
$function
(
$
field
,
$element
))
{
return
get_string
(
'This field is
required'
);
if
(
$function
(
$
value
,
$element
))
{
return
$form
->
i18n
(
'
required'
);
}
return
;
}
if
(
$
field
==
''
||
is_array
(
$field
)
&&
!
empty
(
$field
[
'error'
])
)
{
return
get_string
(
'This field is
required'
);
if
(
$
value
==
''
)
{
return
$form
->
i18n
(
'
required'
);
}
}
/**
* Returns a javascript condition to check whether the field has been specified.
*
* @param string $id id of the field to check
* @return string js condition to check if the field is empty.
* string The error message, if the value is invalid.
*/
function
form_rule_required_js
(
$id
)
{
$r
=
new
StdClass
;
$r
->
condition
=
'$(\''
.
$id
.
'\').value != \'\''
;
$r
->
message
=
get_string
(
'This field is required'
);
return
$r
;
}
?>
htdocs/lib/form/rules/validateoptions.php
View file @
02716408
...
...
@@ -31,12 +31,12 @@ defined('INTERNAL') || die();
* the element. This prevents malicious people from doing things like
* submitting values that aren't in a select box.
*
* @param Form $form The form the rule is being applied to
* @param string $field The field to check
* @param string $element The element being checked
* @return string The error message, if the value is invalid.
* @todo untested :p
*/
function
form_rule_validateoptions
(
$field
,
$element
)
{
function
form_rule_validateoptions
(
Form
$form
,
$field
,
$element
)
{
// Get the value into an array as a key if it's a scalar, since
// the actual check involves array keys
if
(
!
is_array
(
$field
))
{
...
...
@@ -46,7 +46,7 @@ function form_rule_validateoptions($field, $element) {
$allowedvalues
=
array_keys
(
$element
[
'options'
]);
foreach
(
array_keys
(
$field
)
as
$key
)
{
if
(
!
in_array
(
$key
,
$allowedvalues
))
{
return
get_string
(
'optionnotavailableforelement'
,
'error'
);
return
sprintf
(
$form
->
i18n
(
'validateoptions'
),
$key
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment