rsanchez / resource_router

Resource Router for ExpressionEngine
MIT License
48 stars 12 forks source link

mapping get/post variables to segments #31

Closed robsonsobral closed 8 years ago

robsonsobral commented 8 years ago

Hi!

Is it possible to use variables from a submitted form on a redirect? I'm thinking on something like:

$router->redirect('search/'.$year.$month.$day.'/'.$categories_delimeted_by_whatever.'/'.$keyword);

Thank you!

rsanchez commented 8 years ago

Depends on the kind of form. If it's a POST, you'll need to include a hidden input:

<input type="hidden" name="csrf_token" value="{csrf_token}">

You can just grab your form input. You should probably sanitize these inputs.

$year = ee()->input->post('year');
if ( ! preg_match('/^\d{4}$/', $year)) {
    show_error('Invalid year');
}
$router->redirect('search/'.$year);
robsonsobral commented 8 years ago

Thank you, @rsanchez !

I gonna try it!

P.S.: Maybe it's an interesting use case for the samples.

P.S.2: Isn't better to use $year = ee()->input->post('year', TRUE);?

Thank you!

rsanchez commented 8 years ago

Re: PS2

XSS clean is not really necessary, since I'm ensuring it's a 4 digit number and nothing else using preg_match.

robsonsobral commented 8 years ago

Wow! I gonna close this! I'm sorry!

And thank you!