I just tried to use “parse_URL” to extract the host, just as a simple way of cleaning up URLs.
It works, but if there is more than one failed submission of the form due to other errors, the website field is empty when the form is redisplayed for the second time. On the first redisplay, I can see the parse URL function in action, but after any other error, the data is lost.
The gist of my code is:
$_POST['domain'] = parse_url($_POST['domain'], PHP_URL_HOST);
// tidy other fields (e.g. trim and htmlspecialchars)
// validate all fields with regexes and create error messages if needed
// return form with error messages and data
I’m still fairly novice at PHP, with patchy knowledge of it.