A
A
Albert19912019-08-19 17:21:07
PHP
Albert1991, 2019-08-19 17:21:07

Why 404 error when processing form on Slim?

Hello. For some reason, when submitting the form to Slim, an error 404. Tell me where I could make a mistake, please.

<form action="/auth" method="post" >
    <div>
        <label>
            Ваш логин
            <input type="text" name="user[login]" value="<?= htmlspecialchars($user['login'] ?? '') ?>" required>
        </label>
    </div>
    <div>
        <label>
            Subdomain
            <input type="text" name="user[subdomain]" value="<?= htmlspecialchars($user['subdomain'] ?? '') ?>" required>
        </label>
    </div>
    <div>
        <label>
            ApiKey
            <input type="text" name="user[apiKey]" value="<?= htmlspecialchars($user['apiKey'] ?? '') ?>" required>
        </label>
    </div>
    <input type="submit" value="Показать сделки за этот месяц">
</form>

and there is a handler
<?php

namespace App;

require __DIR__ . '/../vendor/autoload.php';

use Slim\Factory\AppFactory;
use DI\Container;
use function functions\auth;

$container = new Container();
$container->set('renderer', function () {
    return new \Slim\Views\PhpRenderer(__DIR__ . '/../templates');
});
$container->set('flash', function () {
    return new \Slim\Flash\Messages();
});

AppFactory::setContainer($container);
$app = AppFactory::create();
$app->addErrorMiddleware(true, true, true);

$app->get('/', function ($request, $response) {
    return $this->get('renderer')->render($response, 'index.phtml');
});

$app->post('/auth', function ($request, $response) {
    $user = $request->getParsedBodyParam('user');
    $login = $user['login'];
    $subdomain = $user['subdomain'];
    $apiKey = $apiKey['login'];
    if (auth($login, $apiKey, $subdomain)) {
        $this->get('flash')->addMessage('success', 'Авторизация успешна');
    } else {
        $this->get('flash')->addMessage('error', 'Ошибка авторизации');
    }
    return return $response->withHeader('Location', '/')->withStatus(302);
});

$app->run();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question