The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

POST Form page not found

rpbodley's Avatar

rpbodley

18 Feb, 2016 06:28 PM

Hi,

I am hoping someone can help me. I have Slim installed and working. The problem is I have an HTML form that submits to a routed URL and it says "404 page not found" but if I manually go to this page without submitting the form it works fine. If I use GET it also works fine when submitting the form.

My Form on /store routing

<form action='../checkout/demo' method='POST'>
<input name='fullname' id='fullname' type='text' placeholder='Fullname'> <input name='email' placeholder='Email Address' type='text'> <input name='address1' placeholder='Address' type='text'>
<input name='city' placeholder='City' type='text'> <input name='state' placeholder='State' type='text'> <input name='zip' placeholder='Zip/Postal Code' type='text'>
<button type='submit'>Pay for my Items Now!</button> </form>

My Router

require "Slim/Slim.php";
\Slim\Slim::registerAutoloader();
$router = new \Slim\Slim(); 
$router->get("/store/:storeUrl", function ($storeUrl) {
    //This just adds the form to this url
    $controller = new Controller();
    $controller->mainStore($storeUrl);
});
$router->get("/checkout/:storeUrl", function ($storeUrl) use ($router) {
    echo "string";
});
$router->run();

Any help would be greatly appreciated!

  1. 1 Posted by Johan on 19 Feb, 2016 02:14 PM

    Johan's Avatar

    Hi,

    you need a post route, because your form has method='POST'

    $router->post('/checkout/:storeUrl' , function ($storeUrl) ...
    

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac