summaryrefslogtreecommitdiff
path: root/src/view/FormBuilder.php
blob: 7a2adcbaf16ab0bbd41a4ad068c5bfaad1a5e93e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
// src/view/FormBuilder.php

declare(strict_types=1);

use App\Entity\Node;

class FormBuilder extends AbstractBuilder
{
    public function __construct(Node $node)
    {
        parent::__construct($node);
        $viewFile = self::VIEWS_PATH . $node->getName() . '.php';
        
        if(file_exists($viewFile))
        {
            if(!empty($node->getNodeData()->getData()))
            {
                extract($node->getNodeData()->getData());
            }

            $captcha = new Captcha;
            $_SESSION['captcha'] = $captcha->getSolution();

            $email = $email ?? Config::$email_dest;

            $admin_content = '';
            if($_SESSION['admin'])
            {
                $admin_content = '<div class="admin_form">
                    <p>
                        <label for="recipient">E-mail de destination de ce formulaire</label>
                        <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value="' . $email . '">
                        <input type="hidden" id="recipient_hidden" value="">
                        <button onclick="changeRecipient(' . $node->getNodeData()->getId() . ')">Valider</button>
                    </p>
                    <p><button onclick="sendTestEmail(' . $node->getNodeData()->getId() . ')">Envoi d\'un e-mail de test</button></p>
                    <p class="test_email_success full_width_column"></p>
                </div>' . "\n";
            }

            ob_start();
            require $viewFile;
            $this->html = ob_get_clean(); // pas de concaténation ici, on écrase
        }
    }
}