Home › Forums › Feature Requests › Optional protocol/scheme in URL field type › Reply To: Optional protocol/scheme in URL field type
While this would be nice, this is not something that ACF is actually validating or forcing. The protocol needing to be entered is something that the browser is doing. ACF uses <input type="url">
and this causes the browser to do validation. You can test this by creating a simple html page with a form and a url input.
ACF is only catching the error already produced and displaying it in the same way as other errors for other fields.
I generally use a text type field for URLs and do my own validation with an acf/validate_value filter so that I can allow clients to enter any valid href value.
function validate_text_as_href($valid, $value, $field, $input) {
if (!$valid) {
return $valid;
}
if (!empty($value)) {
if (!preg_match('%^(https?\://|ftp\://|/|#|mailto\:|sms\:|tel\:)%', $value)) {
$valid = 'Enter a Valid HREF Value';
}
}
return $valid;
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.