Route parameters with #


#1

or hash character is not passing in route parameters.

$this->post(’/postText/{data}’, function ($request, $response, $args) {
# code…
if($request->isPost()) {
echo $feed = $args[‘data’]; //My input is ’ Hello world #world’. Output is only ‘Hello world’
}
});


#2

Even here i have posted hash character but it is not visible on page why??


#3

Without more info, that is the behavior I would expect. Can you post an example of the URL you are requesting and the route definition?


#4

$this->post(’/postText/{data}’, function ($request, $response, $args) {
# code…
if($request->isPost()) {
echo $feed = $args[‘data’]; //My input is ’ Hello world #world’. Output is only ‘Hello world’
}
});


#5

What does this give you?

$this->post(’/postText/{data}’, function ($request, $response, $args) {
    $fragment = $request->getFragment();
    echo $fragment;
});

#6

still facing same problem


#7

I’m not sure I understand what you are trying to do. Browser’s don’t send the fragment (the part after the #).


#8

Is there any solution of this problem??


#9

I got this solution from stackoverflow and its working https://stackoverflow.com/questions/47123743/hash-is-not-passing-as-route-parameter-in-slim-framework-api

The # is a special character in the url spec, you can’t use it as input unless encoded.

From php use: urlencode() and urldecode()

From js use something like: encodeURIComponent()

That way you’ll get %23 instead of #, which will get stripped.


#10

That might work… you would likely need to use regex to match the route and need two parameters. But why not just use a different delimiter than #? That would be much easier.


#11

I am not using # as delimiter, I m passing # as input.


#12

The main problem is that the browser won’t even send a request with a fragment part. The fragment part is resolved right there in the browser. So it’s reachable through JavaScript.