Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
a78890d5
Commit
a78890d5
authored
Nov 23, 2007
by
skodak
Browse files
MDL-12133 validate() method tidying up; merged from MOODLE_19_STABLE
parent
010aa4da
Changes
44
Hide whitespace changes
Inline
Side-by-side
admin/uploaduser_form.php
View file @
a78890d5
...
...
@@ -269,8 +269,8 @@ class admin_uploaduser_form2 extends moodleform {
/**
* Server side validation.
*/
function
validation
(
$data
)
{
$errors
=
ar
ray
(
);
function
validation
(
$data
,
$files
)
{
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
$columns
=&
$this
->
_customdata
;
$optype
=
$data
[
'uutype'
];
...
...
@@ -325,11 +325,7 @@ class admin_uploaduser_form2 extends moodleform {
}
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
}
?>
course/edit_form.php
View file @
a78890d5
...
...
@@ -405,8 +405,8 @@ class course_edit_form extends moodleform {
/// perform some extra moodle validation
function
validation
(
$data
)
{
$errors
=
ar
ray
(
);
function
validation
(
$data
,
$files
)
{
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
if
(
$foundcourses
=
get_records
(
'course'
,
'shortname'
,
$data
[
'shortname'
]))
{
if
(
!
empty
(
$data
[
'id'
]))
{
unset
(
$foundcourses
[
$data
[
'id'
]]);
...
...
@@ -426,11 +426,7 @@ class course_edit_form extends moodleform {
}
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
}
?>
course/import/activities/import_form.php
View file @
a78890d5
...
...
@@ -25,8 +25,8 @@ class course_import_activities_form_1 extends moodleform {
}
function
validation
(
$data
)
{
return
true
;
function
validation
(
$data
,
$files
)
{
return
parent
::
validation
(
$data
,
$files
)
;
}
}
...
...
@@ -52,7 +52,7 @@ class course_import_activities_form_2 extends moodleform {
}
function
validation
(
$data
)
{
function
validation
(
$data
,
$files
)
{
return
true
;
}
...
...
course/moodleform_mod.php
View file @
a78890d5
...
...
@@ -65,8 +65,8 @@ class moodleform_mod extends moodleform {
}
}
if
(
$
mform
->
elementExists
(
'
groupmode
'
)
)
{
if
(
$
COURSE
->
groupmode
force
)
{
if
(
$
COURSE
->
groupmode
force
)
{
if
(
$
mform
->
elementExists
(
'
groupmode
'
)
)
{
$mform
->
hardFreeze
(
'groupmode'
);
// groupmode can not be changed if forced from course settings
}
}
...
...
@@ -86,8 +86,9 @@ class moodleform_mod extends moodleform {
}
// form verification
function
validation
(
$data
)
{
function
validation
(
$data
,
$files
)
{
global
$COURSE
;
$errors
=
parent
::
validation
(
$data
,
$files
);
$mform
=&
$this
->
_form
;
...
...
@@ -115,11 +116,7 @@ class moodleform_mod extends moodleform {
}
}
if
(
count
(
$errors
)
==
0
)
{
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
/**
...
...
@@ -181,8 +178,12 @@ class moodleform_mod extends moodleform {
}
$mform
->
addElement
(
'header'
,
'modstandardelshdr'
,
get_string
(
'modstandardels'
,
'form'
));
if
(
$features
->
groups
){
$mform
->
addElement
(
'modgroupmode'
,
'groupmode'
,
get_string
(
'groupmode'
));
if
(
$features
->
groups
)
{
$options
=
array
(
NOGROUPS
=>
get_string
(
'groupsnone'
),
SEPARATEGROUPS
=>
get_string
(
'groupsseparate'
),
VISIBLEGROUPS
=>
get_string
(
'groupsvisible'
));
$mform
->
addElement
(
'select'
,
'groupmode'
,
get_string
(
'groupmode'
),
$options
,
NOGROUPS
);
$mform
->
setHelpButton
(
'groupmode'
,
array
(
'groupmode'
,
get_string
(
'groupmode'
)));
}
if
(
!
empty
(
$CFG
->
enablegroupings
))
{
...
...
course/request_form.php
View file @
a78890d5
...
...
@@ -31,8 +31,8 @@ class course_request_form extends moodleform {
$this
->
add_action_buttons
();
}
function
validation
(
$data
)
{
$errors
=
ar
ray
(
);
function
validation
(
$data
,
$files
)
{
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
$foundcourses
=
null
;
$foundreqcourses
=
null
;
...
...
@@ -67,12 +67,8 @@ class course_request_form extends moodleform {
}
}
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
}
...
...
enrol/authorize/enrol_form.php
View file @
a78890d5
...
...
@@ -171,11 +171,10 @@ class enrol_authorize_form extends moodleform
$this
->
add_action_buttons
(
false
,
get_string
(
'sendpaymentbutton'
,
'enrol_authorize'
));
}
function
validation
(
$data
)
function
validation
(
$data
,
$files
)
{
global
$CFG
;
$errors
=
array
();
$errors
=
parent
::
validation
(
$data
,
$files
);
if
(
AN_METHOD_CC
==
$data
[
'paymentmethod'
])
{
...
...
@@ -209,7 +208,7 @@ class enrol_authorize_form extends moodleform
}
}
return
(
empty
(
$errors
)
?
true
:
$errors
)
;
return
$errors
;
}
private
function
other_method_available
(
$currentmethod
)
...
...
grade/edit/outcome/edit_form.php
View file @
a78890d5
...
...
@@ -135,8 +135,8 @@ class edit_outcome_form extends moodleform {
}
/// perform extra validation before submission
function
validation
(
$data
)
{
$errors
=
ar
ray
(
);
function
validation
(
$data
,
$files
)
{
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
if
(
$data
[
'scaleid'
]
<
1
)
{
$errors
[
'scaleid'
]
=
get_string
(
'required'
);
...
...
@@ -149,11 +149,7 @@ class edit_outcome_form extends moodleform {
}
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
...
...
grade/edit/scale/edit_form.php
View file @
a78890d5
...
...
@@ -107,10 +107,10 @@ class edit_scale_form extends moodleform {
}
/// perform extra validation before submission
function
validation
(
$data
)
{
function
validation
(
$data
,
$files
)
{
global
$CFG
,
$COURSE
;
$errors
=
ar
ray
(
);
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
// we can not allow 2 scales with the same exact scale as this creates
// problems for backup/restore
...
...
@@ -148,11 +148,7 @@ class edit_scale_form extends moodleform {
}
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
}
...
...
grade/edit/tree/calculation_form.php
View file @
a78890d5
...
...
@@ -82,8 +82,8 @@ class edit_calculation_form extends moodleform {
}
/// perform extra validation before submission
function
validation
(
$data
)
{
$errors
=
ar
ray
(
);
function
validation
(
$data
,
$files
)
{
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
$mform
=&
$this
->
_form
;
...
...
@@ -97,11 +97,7 @@ class edit_calculation_form extends moodleform {
}
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
}
...
...
grade/edit/tree/item_form.php
View file @
a78890d5
...
...
@@ -318,8 +318,8 @@ class edit_item_form extends moodleform {
/// perform extra validation before submission
function
validation
(
$data
)
{
$errors
=
ar
ray
(
);
function
validation
(
$data
,
$files
)
{
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
if
(
array_key_exists
(
'idnumber'
,
$data
))
{
if
(
$data
[
'id'
])
{
...
...
@@ -351,11 +351,7 @@ class edit_item_form extends moodleform {
}
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
}
...
...
grade/edit/tree/outcomeitem_form.php
View file @
a78890d5
...
...
@@ -216,8 +216,8 @@ class edit_outcomeitem_form extends moodleform {
/// perform extra validation before submission
function
validation
(
$data
)
{
$errors
=
ar
ray
(
);
function
validation
(
$data
,
$files
)
{
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
if
(
array_key_exists
(
'idnumber'
,
$data
))
{
if
(
$data
[
'id'
])
{
...
...
@@ -230,11 +230,7 @@ class edit_outcomeitem_form extends moodleform {
}
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
}
...
...
grade/import/xml/grade_import_form.php
View file @
a78890d5
...
...
@@ -84,7 +84,7 @@ class grade_import_form extends moodleform {
}
function
validation
(
$data
,
$files
)
{
$err
=
ar
ray
(
);
$err
=
p
ar
ent
::
validation
(
$data
,
$files
);
if
(
empty
(
$data
[
'url'
])
and
empty
(
$files
[
'userfile'
]))
{
if
(
array_key_exists
(
'url'
,
$data
))
{
$err
[
'url'
]
=
get_string
(
'required'
);
...
...
@@ -97,11 +97,7 @@ class grade_import_form extends moodleform {
$err
[
'url'
]
=
get_string
(
'error'
);
}
if
(
count
(
$err
)
==
0
){
return
true
;
}
else
{
return
$err
;
}
return
$err
;
}
}
?>
grade/report/grader/preferences_form.php
View file @
a78890d5
...
...
@@ -191,13 +191,8 @@ class grader_report_preferences_form extends moodleform {
}
/// perform some extra moodle validation
function
validation
(
$data
){
$errors
=
array
();
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
function
validation
(
$data
,
$files
)
{
return
parent
::
validation
(
$data
,
$files
);
}
}
?>
group/autogroup_form.php
View file @
a78890d5
...
...
@@ -91,7 +91,7 @@ class autogroup_form extends moodleform {
function
validation
(
$data
,
$files
)
{
global
$CFG
,
$COURSE
;
$errors
=
ar
ray
(
);
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
if
(
$data
[
'allocateby'
]
!=
'no'
)
{
if
(
!
$users
=
groups_get_potential_members
(
$data
[
'courseid'
],
$data
[
'roleid'
]))
{
...
...
group/group_form.php
View file @
a78890d5
...
...
@@ -42,10 +42,10 @@ class group_form extends moodleform {
$this
->
add_action_buttons
();
}
function
validation
(
$data
)
{
function
validation
(
$data
,
$files
)
{
global
$COURSE
;
$errors
=
ar
ray
(
);
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
$name
=
trim
(
stripslashes
(
$data
[
'name'
]));
if
(
$data
[
'id'
]
and
$group
=
get_record
(
'groups'
,
'id'
,
$data
[
'id'
]))
{
...
...
@@ -59,11 +59,7 @@ class group_form extends moodleform {
$errors
[
'name'
]
=
get_string
(
'groupnameexists'
,
'group'
,
$name
);
}
if
(
count
(
$errors
)
>
0
)
{
return
$errors
;
}
else
{
return
true
;
}
return
$errors
;
}
function
get_um
()
{
...
...
group/grouping_form.php
View file @
a78890d5
...
...
@@ -27,10 +27,10 @@ class grouping_form extends moodleform {
$this
->
add_action_buttons
();
}
function
validation
(
$data
)
{
function
validation
(
$data
,
$files
)
{
global
$COURSE
;
$errors
=
ar
ray
(
);
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
$name
=
trim
(
stripslashes
(
$data
[
'name'
]));
if
(
$data
[
'id'
]
and
$grouping
=
get_record
(
'groupings'
,
'id'
,
$data
[
'id'
]))
{
...
...
@@ -44,11 +44,7 @@ class grouping_form extends moodleform {
$errors
[
'name'
]
=
get_string
(
'groupingnameexists'
,
'group'
,
$name
);
}
if
(
count
(
$errors
)
>
0
)
{
return
$errors
;
}
else
{
return
true
;
}
return
$errors
;
}
}
...
...
lib/formslib.php
View file @
a78890d5
...
...
@@ -335,15 +335,16 @@ class moodleform {
$data
=
$mform
->
exportValues
(
null
,
true
);
$moodle_val
=
$this
->
validation
(
$data
,
$files
);
if
(
$moodle_val
!==
true
)
{
if
((
is_array
(
$moodle_val
)
&&
count
(
$moodle_val
)
!==
0
))
{
foreach
(
$moodle_val
as
$element
=>
$msg
)
{
$mform
->
setElementError
(
$element
,
$msg
);
}
$moodle_val
=
false
;
}
else
{
$moodle_val
=
true
;
if
((
is_array
(
$moodle_val
)
&&
count
(
$moodle_val
)
!==
0
))
{
// non-empty array means errors
foreach
(
$moodle_val
as
$element
=>
$msg
)
{
$mform
->
setElementError
(
$element
,
$msg
);
}
$moodle_val
=
false
;
}
else
{
// anything else means validation ok
$moodle_val
=
true
;
}
$validated
=
(
$internal_val
and
$moodle_val
and
$file_val
);
...
...
@@ -511,8 +512,8 @@ class moodleform {
*
* @param array $data array of ("fieldname"=>value) of submitted data
* @param array $files array of uploaded files "element_name"=>tmp_file_path
* @return
mixed an
array of "element_name"=>"error_description" if there are errors
.
*
true
or an empty array if everything is OK.
* @return array of "element_name"=>"error_description" if there are errors
,
*
or an empty array if everything is OK
(true allowed for backwards compatibility too)
.
*/
function
validation
(
$data
,
$files
)
{
return
array
();
...
...
login/change_password_form.php
View file @
a78890d5
...
...
@@ -40,9 +40,9 @@ class login_change_password_form extends moodleform {
}
/// perform extra password change validation
function
validation
(
$data
)
{
function
validation
(
$data
,
$files
)
{
global
$USER
;
$errors
=
ar
ray
(
);
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
update_login_count
();
...
...
@@ -73,7 +73,7 @@ class login_change_password_form extends moodleform {
return
$errors
;
}
return
true
;
return
$errors
;
}
}
?>
login/forgot_password_form.php
View file @
a78890d5
...
...
@@ -19,10 +19,10 @@ class login_forgot_password_form extends moodleform {
$this
->
add_action_buttons
(
true
,
get_string
(
'ok'
));
}
function
validation
(
$data
)
{
function
validation
(
$data
,
$files
)
{
global
$CFG
;
$errors
=
ar
ray
(
);
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
if
((
!
empty
(
$data
[
'username'
])
and
!
empty
(
$data
[
'email'
]))
or
(
empty
(
$data
[
'username'
])
and
empty
(
$data
[
'email'
])))
{
$errors
[
'username'
]
=
get_string
(
'usernameoremail'
);
...
...
@@ -57,11 +57,7 @@ class login_forgot_password_form extends moodleform {
}
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
}
...
...
login/signup_form.php
View file @
a78890d5
...
...
@@ -79,9 +79,9 @@ class login_signup_form extends moodleform {
$mform
->
applyFilter
(
'username'
,
'trim'
);
}
function
validation
(
$data
)
{
function
validation
(
$data
,
$files
)
{
global
$CFG
;
$errors
=
ar
ray
(
);
$errors
=
p
ar
ent
::
validation
(
$data
,
$files
);
$authplugin
=
get_auth_plugin
(
$CFG
->
registerauth
);
...
...
@@ -122,15 +122,12 @@ class login_signup_form extends moodleform {
}
$errmsg
=
''
;
if
(
!
check_password_policy
(
$data
[
'password'
],
$errmsg
))
{
$errors
[
'password'
]
=
$errmsg
;
}
if
(
0
==
count
(
$errors
)){
return
true
;
}
else
{
return
$errors
;
}
return
$errors
;
}
...
...
Prev
1
2
3
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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