Form validation: error message |
Base URL for registration page:
Code: http://localhost/codeigniter-project/users/register Registration page: PHP Code: <?php echo validation_errors('<p class="bg-danger">'); ?> Controller: PHP Code: class Users extends CI_Controller When I open the URL for the very first time there were no validation errors produced. But if I try to fill the form and for example provide only 'fisrt name' (and do not provide 'last name'), then validation errors generated and displayed on the register page. So why were no errors genererated in the beginning, when I open the base url for the very first time?
Because you haven't submitted any data. It can't validate something that aren't there.
It works as intendent.
Loading the page the first time is a GET request. Validation only tests the rules when responding to a POST request and a form "submit" is (should be) a POST operation. (Which is just another way to say what @jreklund said.)
Quote:When I open the URL for the very first time there were no validation errors produced. Validation errors are meant to inform the user that he didn't fill in the form correctly. Why would you want to show validation errors before the user even made one attempt to fill in the form?
|
Welcome Guest, Not a member yet? Register Sign In |