Search

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!!

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.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details