4

I want to redirect to a page (error.php, for example) depending on the info in a form in my website. I managed to log an error like this:

if ($date > $curdate) {
    return $response
        ->withStatus(406)
        ->withHeader('Content-Type', 'text/html')
        ->write('You can\'t select dates in the future!');
}

How can I do it so it sends you to a page with that error in particular instead of logging/requesting it in the network tab?

Right now I get this:

Request URL:http://raspberrypi/chartAPI/api/{id}/{date1}/{date2}
Request Method:POST
Status Code:406 Not Acceptable
Remote Address:192.168.0.80:80
Referrer Policy:no-referrer-when-downgrade

Which is almost working as intended. What I want to do is for it to send me to "http://raspberrypi/chartAPI/error/406" (for example), and display the contents in a file called 406.php (or error406.php, or error.php or whatever call it).

I managed to do something with this:

return $response->withRedirect("error.php");

But I get this:

Request URL:http://raspberrypi/chartAPI/api/{id}/{date1}/error.php
Request Method:GET
Status Code:405 Method Not Allowed

And slim throws this error:

Method not allowed. Must be one of: POST

Why is it removing {date2}? And why is it asking for a POST method?

This question is a continuation of this one, but due to how this website handles these "old" questions, mine got pushed down and regardless of how many edits I put, it doesn't get any attention anymore.

Community
  • 1
  • 1
Newwt
  • 491
  • 1
  • 5
  • 22
  • 1
    Possible duplicate of [Redirecting with error on Slim Framework](http://stackoverflow.com/questions/43611649/redirecting-with-error-on-slim-framework) – geggleto May 01 '17 at 14:11
  • @geggleto That's what I said at the end of the question. – Newwt May 02 '17 at 06:59

1 Answers1

1

When you are using withRedirect, use a Route URL not a file to browse

The Error is about using GET Method Where the Route needs POST

I think this is Because you use a file to redirect to,Then the method will be Only GET not POST or others like a browser

I don't Know Why you are using POST whenever you pass parameters in URL ?!

Ramy hakam
  • 522
  • 1
  • 6
  • 19