Jeradin / acf-website-field

Advanced Custom Fields add-on for Website URLs, allows for website URL, title and a checkbox to open externally or internally
59 stars 14 forks source link

Possible to add input validation #22

Closed Woolball closed 9 years ago

Woolball commented 10 years ago

Thanks for the plugin :)

It is possible to add simple HTML input validation by setting the input field type to "url".

Commit: 972c3e60da6c3d2656cb98638e9194d7d1dd4143 Location: website_url.php (line: 168) Suggested modification:

echo '<td><input type="url" value="' . $link_title . '" id="' . $key . '" class="' . $class . '" name="'.$key.'[title]" /></td>';
adam-jones-net commented 10 years ago

This is a quick fix and doesn't solve all issues, in fact it makes more issues.

1) compatibility on old browsers 2) the specification for browers url validation that is run when a field is set to type="url" ensures that the url you enter MUST start with http://, https:// etc. Yet this is in direct contradiction to how the plugin currently works. As anyone who uses the plugin will have seen, a tip on screen states you don't have to add http as it will be done by the plugin if needed.

adam-jones-net commented 10 years ago

+1 though for a propper fix on this! The sole reason I downloaded the plugin was to have an ACF field that included url validation and this doesn't do it!

Woolball commented 10 years ago

Yes, you are right.

One possibility is to use a regular expression. There is a lot of choice on this front as it appears that url validation is not simple to achieve for the general case: http://mathiasbynens.be/demo/url-regex

I ended up using a simple regular expression with a custom-generated form field.

Jeradin commented 9 years ago

Sorry for the long delay, if anyone is still using this it now validates in the admin section and also uses HTML5 type="url" for validation.