Support

Account

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;
    }