How to check url but ignore if http: // or empty?

I want to check the form field for a URL. I set the default value for the http: // field. When the user does not enter the URL and leaves http: //, he speaks of an invalid URL. No url is required, so if it is only http: // it should not display an error message. How can I make it ignore if a person sends http: // as a URL?

thanks

+2
source share
1 answer

http: // is not a valid URL, so if you want to allow it there are 2 options anyway

hope that helps

EDIT

I forgot: you do not need to set the required, but 'allowEmpty' => true

required → the form must contain the xyz field, which is sent to the server

allowEmpty -> the field may be empty


I added a link to the callback function above, but anyway ... here:

in your model class (I just assume that it is User ):

 class User extends AppModel { .. function beforeValidate() { if (isset($this->data['User']['url']) && $this->data['User']['url'] == 'http://') { $this->data['User']['url'] = ''; } return true; } .. } 

+3
source

Source: https://habr.com/ru/post/1336837/


All Articles