Problem with validation |
Please, give me an advice
If he has an item in the form that can remain empty (the user does not have to fill it in), then I have a problem with validation. For example, I have an email item that does not need to be filled out Code: <input type = "text" name = "email" value = "<? php echo set_value ('email');?>" size = "50" /> But I have a validation written on it, which in my opinion should take place only when something is entered in the item. Code: 'email' => ['label' => 'Email Address', 'rules' => 'valid_email|max_length [150]'] If I do not fill in the email and send the form, it reports the error "The Email Address field must contain a valid email address." Can you please advise me what to do with it? Thank you
Just delete
Code: valid_email| Code: 'email' => ['label' => 'Email Address', 'rules' => 'callback_email_check|max_length [150]'] Code: public function email_check($str) https://codeigniter.com/userguide3/libra...on-methods
Add permit_empty to your rules: http://codeigniter.com/user_guide/librar...able-rules
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Thank you. My fault. Only now have I found out that validation works differently than in CI3 and in "Available Rules", it is now "permit_empty".
|
Welcome Guest, Not a member yet? Register Sign In |