i’ve been doing form submission and validationss.
i have been writing long codes to pass data from the controller/php page to a validation class and then pass it back to be displayed on the view.
for instance:
controller
if (isset($_POST["btnSubmit")) {
$result = ClassSomething::validateForm($_POST);
if (!$result) { //no error
ClassSomething::insertRecord(...);
} else {
$error = $result;
}
}
class ClassSomething {
public function validateForm($str) {
if ($str == "") {
return "error messagesss";
}
}
}
and somewhere in the html, i would display $error
is there a better way to do validation in php??
is there validation codes which can be reuse rather then doing it for every form??
tks in adv.
How can I validate POST data for user login form with this class in Kohana: