Support

Account

Home Forums Feature Requests Optional protocol/scheme in URL field type

Helping

Optional protocol/scheme in URL field type

  • Currently users cannot enter values in URL fields without the scheme.
    End Users may not know the concept of protocols / schemes and therefore may skip it which results in invalid URL validation messages.

    An option to disable scheme validation would be nice so urls like:
    example.com
    advancedcustomfields.com

    are accepted by URL fields.

  • 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;
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.