summaryrefslogtreecommitdiff
path: root/src/view/FormBuilder.php
blob: b3a96f3bb0e0f3f6dea15834de13900bbc00c50a (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
48
49
50
51
<?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());
            }

            $action_url = new URL(['page' => CURRENT_PAGE]);
            $captcha = new Captcha;
            $_SESSION['captcha'] = $captcha->getSolution();

            $no_recipient_warning = '';
            $admin_content = '';
            if($_SESSION['admin'])
            {
                $admin_content = '<script src="js/form.js"></script>
                <h3>Configuration du formulaire</h3>
                <div class="admin_form">
                    <label for="recipient">E-mail du destinataire</label>
                    <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value="">
                    <button onclick="changeRecipient()">Valider</button>
                </div>';
            }

            $recipient_found = false;
            // recherche BDD
            
            if(!$recipient_found){ // vérifier qu'une adresse de destination est bien configurée
                $no_recipient_warning = '<p class="no_recipient_warning">Aucune adresse de destination n\'a été configurée, envoi d\'e-mail impossible!</p>';
            }

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