I'm Using the Slim framework and trying to get a basic form up and running with some php scripting. Index.php contains a form that when submitted will execute a second php script called request_variable.php, which will output the contents of the form. Here is my code:
Index.php
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require '../../vendor/autoload.php';
$app = new \Slim\App;
$app->get('/',function(Request $request,Response $response){
$output = <<< HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="AUthor" content="tester" />
<title> form example</title>
</head>
<body>
<form action="request_variable.php" method="post">
<input type="text" name="firstname" placeholder="First Name" />
<input type="text" name"lastname" placeholder="Last Name" />
<input type="submit" name="submit" />
</form>
</body>
</html>
HTML;
echo $output;
});
$app->run();
request_variable.php
<?php
use Slim\Http\Request;
use Slim\Http\Response;
require '../../vendor/autoload.php';
$app = new \Slim\App;
$app->post('/',function(Request $request,Response $response) use ($app)
{
$parameters = $request->getParsedBody();
echo $parameters['firstname'];
echo $parameters['lastname'];
}
$app->run();
The problem
I then test index.php:
php -S localhost:8000 index.php
I then enter the address in my web browser. The form is visible and appears to be ok. I enter my firstname and lastname, however as soon as i click submit i recieve the following error:
Method not allowed, must be one of:GET
As a php novice and web appication development novice i'm wondering why this is occuring? do i need to use get instead of post then or is it another issue? Thanks in advance.