We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Redirecting to a URL specified as a parameter value

Development and Programming

Ben Kimball (UT)'s avatar
Ben Kimball (UT)
33 posts
17 years ago
Ben Kimball (UT)'s avatar Ben Kimball (UT)

This frustrated me for a while. I found a workaround, but it’s really ugly. Hopefully you guys can tell me where I’m going wrong.

I have a custom plugin, invoked like so:

{exp:my_registration:process to="http://www.site.com/registration/confirm"}

The plugin processes the values specified by the user, which it gets from $IN->GBL(‘blah’, ‘POST’), and when it’s finished, it uses $FNS->redirect() to send the user to the URL specified in the to parameter.

Trouble is, $TMPL->fetch_param(‘to’) returns

http//www.site.com/registration/form

So my workaround is to do the reverse of what core.template.php does on line 444:

443: // Replace forward slashes with entity to prevent preg_replace errors.
444: $this->template = str_replace('/', SLASH, $this->template);

Namely:

if( ! $to_url = $TMPL->fetch_param('to')) {
    $to_url = 'http://www.default-value.com/';
} else {
    // re-convert / to /, since $TMPL->fetch_param will munge the data
    $to_url = str_replace(SLASH, '/', $to_url);
}

Of course, this stinks.

Another thing that stinks: if there are embedded tags in parameter values, they’re not parsed. So I can’t do this:

{exp:my_registration:process to="{path="registration/confirm"}"}

Is there a simple way for me to parse parameter values, and ensure that forward slashes in them aren’t URL-encoded?

Thanks, Ben

       
Daniel Walton's avatar
Daniel Walton
553 posts
17 years ago
Daniel Walton's avatar Daniel Walton

The slashes are just gonna be that way, so the only workaround for you is to str_replace them.

A neater way for you to accept input from that parameter would be to allow values such as “registration/confirm” for local addresses, and “http://www.example.com” for external ones.

You could then just do a quick strpos()/substr() to see if http is present, if not, run the input through $FNS->create_url(); Im not sure if create_url can handle &# 47;’s, if it can then bonus.

       
Ben Kimball (UT)'s avatar
Ben Kimball (UT)
33 posts
17 years ago
Ben Kimball (UT)'s avatar Ben Kimball (UT)

Ooh, good ideas. Thanks!

Ben

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

This is intended, and your solution is fine. When you need actual slashes, just convert the SLASH constant back to ‘/’.

       
Ben Kimball (UT)'s avatar
Ben Kimball (UT)
33 posts
17 years ago
Ben Kimball (UT)'s avatar Ben Kimball (UT)
This is intended, and your solution is fine. When you need actual slashes, just convert the SLASH constant back to ‘/’.

OK, thanks Derek.

On my last question: can I get EE to parse any EE-code inside the parameter values in the template before it gets to my plugin? And if not, is there a simple way to invoke EE’s parser from my plugin, maybe if I detect LD…RD in the value of the parameter?

Thanks! Ben

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

No, you cannot alter the order of the template parser for variables. The better solution would be to not have your users submit path variables. They should use either a full URL, or the standard template group / template name, which is consistent with the rest of the application. For your part, you can use $FNS->create_url().

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.