<?php

namespace App\Controller;

use App\Core\Controller\Site\PageController;
use Symfony\Component\HttpFoundation\Request;

class BotController extends PageController
{
    public function formWithoutJavascript(Request $request)
    {
        $action = $request->query->get('page');
        $posted = $request->request->all();
        $datas = [];

        if (empty($action) || empty($posted) || !$request->isMethod('POST')) {
            throw $this->createNotFoundException();
        }

        foreach ($posted as $name => $value) {
            if (is_array($value)) {
                foreach ($value as $k => $v) {
                    $datas[$name.'['.$k.']'] = $v;
                }
            } else {
                $datas[$name] = $value;
            }
        }

        return $this->defaultRender('bot/form_without_javascript.html.twig', [
            'action' => $action,
            'datas' => $datas,
        ]);
    }
}
