Adding "http" to url field
This is an open discussion with 7 replies, filed under General.
Search
What about Marks extension? Lazy input correction. you could possibly correct the input upon save by altering this extension?
Thanks moonoo I'll give it a try...!
Assuming you are using a standard event, customize it and alter $_POST
data there.
public function allowEditorToParse(){ return false; } public function execute(){ if( substr($_POST['fields']['url'], 0, 4) !== 'http' ){ $_POST['fields']['url'] = 'http://'.$_POST['fields']['url']; } return parent::execute(); }
Though you should probably also account for https
links.
Hi Vlad,
thanks, my local copy is returning an error for 'protected', I put the execute function as public. Still, while it's identifying the Post token, the script is not saving...
$_POST['url'] = "http://".$_POST['url']; echo $_POST['url'];
This returns "http://"
Thanks!
Aham, my bad. I corrected my previous post. It's actually $_POST['fields']['url']
that you're looking for.
Lovely, thanks!
Create an account or sign in to comment.
Hello,
I have a form where a user can submit links. He can use http:// or just www., but the field[url] accepts only the correct http:// form. Is there a way to prepend at runtime the protocol to any link, if missing?
Thanks!!