Jump to content

Using GET parameters or hashes in the URL fieldtype


Nelson
 Share

Recommended Posts

Hello everyone,

I'm using the URL fieldtype to provide an alternative url for some pages but now I need the ability to use, like the title says, GET parameters or url hashes.

It seems that is unsupported right now, so I would like to ask you good fellows if you have been in the same situation and if there's a solution to this?

Thank you very much.

Link to comment
Share on other sites

Instead of using $_GET you should use $input->get->.

It's like:

$_GET['title']

//same as

$input->get->title

The difference is that $input->get is safe. So no mysql injections and that stuff :)

Edit: I think I misunderstood you're question ;)

Edited by Nico
Link to comment
Share on other sites

I'm sorry, maybe I didn't explained myself well enough.

What I mean is, inside the backoffice I have a field of the type URL that is there if an alternative url is needed for some specific page.

And what I'm trying to do in that field, is to insert urls that may contain GET parameters or url hashes.

For example:

/somepage/?param=stuff or /somepage/#somehash

But when I tried to insert urls like those, the field says that the url inserted is invalid.

Link to comment
Share on other sites

Nelson, try using a fully qualified URL with http:// and domain at the beginning. That will make it use a normal URL filter (which allowed GET vars and hashes). It's more restrictive on URLs where you just specify a path.

Link to comment
Share on other sites

Thank you Ryan. I made a workaround (hardcoded, it was just one url for a menu) for this but it's good to know for the next time I need it.

But I'm curious, why it's restricted this way? It's a security issue?

Link to comment
Share on other sites

But I'm curious, why it's restricted this way? It's a security issue?

There's not a great reason. Basically, if it's a local URL (just as path) then it gets validated consistent with ProcessWire page path rules. If it's a full URL with schema and domain, then it gets validated by PHP's filter_var rules. So it's just a matter of what validates it. Probably what I should do is change the path validation.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...