I'm trying to get into OOP and was checking classes out. I found what I figured would be a simple first choice, which is a form validation class. It works, but it's spitting out a warning message telling me it's missing an argument, which is what the class is supposed to be checking for.
I know I could suppress it, but I'd rather know if anything can be done to fix it.
Warning: Missing argument 1 for validate() in /myscript/ on line 82
// The errored line
function validate($theinput,$description = ''){
My class:
PHP Code:
class Validate {
var $errors;
function validate($theinput,$description = ''){
if (trim($theinput) != "") {
return true;
}else{
$this->errors[] = $description;
return false;
}
}
function foundErrors() {
if (count($this->errors) > 0){
return true;
}else{
return false;
}
}
function listErrors($delim = ' '){
return implode($delim,$this->errors);
}
}
Other code:
PHP Code:
$validator = new Validate();
$validator->validate($_POST["user"],'Username');
$validator->validate($_POST["pass"],'Password');
if ( $validator->foundErrors() ){
echo 'The following fields were empty: <br />'.$validator->listErrors('<br />');
}else{
// rest of my code
}
Bookmarks