diff options
Diffstat (limited to 'src/view/FormBuilder.php')
| -rw-r--r-- | src/view/FormBuilder.php | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/view/FormBuilder.php b/src/view/FormBuilder.php new file mode 100644 index 0000000..b3a96f3 --- /dev/null +++ b/src/view/FormBuilder.php | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | <?php | ||
| 2 | // src/view/FormBuilder.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use App\Entity\Node; | ||
| 7 | |||
| 8 | class FormBuilder extends AbstractBuilder | ||
| 9 | { | ||
| 10 | public function __construct(Node $node) | ||
| 11 | { | ||
| 12 | parent::__construct($node); | ||
| 13 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; | ||
| 14 | |||
| 15 | if(file_exists($viewFile)) | ||
| 16 | { | ||
| 17 | if(!empty($node->getNodeData()->getData())) | ||
| 18 | { | ||
| 19 | extract($node->getNodeData()->getData()); | ||
| 20 | } | ||
| 21 | |||
| 22 | $action_url = new URL(['page' => CURRENT_PAGE]); | ||
| 23 | $captcha = new Captcha; | ||
| 24 | $_SESSION['captcha'] = $captcha->getSolution(); | ||
| 25 | |||
| 26 | $no_recipient_warning = ''; | ||
| 27 | $admin_content = ''; | ||
| 28 | if($_SESSION['admin']) | ||
| 29 | { | ||
| 30 | $admin_content = '<script src="js/form.js"></script> | ||
| 31 | <h3>Configuration du formulaire</h3> | ||
| 32 | <div class="admin_form"> | ||
| 33 | <label for="recipient">E-mail du destinataire</label> | ||
| 34 | <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value=""> | ||
| 35 | <button onclick="changeRecipient()">Valider</button> | ||
| 36 | </div>'; | ||
| 37 | } | ||
| 38 | |||
| 39 | $recipient_found = false; | ||
| 40 | // recherche BDD | ||
| 41 | |||
| 42 | if(!$recipient_found){ // vérifier qu'une adresse de destination est bien configurée | ||
| 43 | $no_recipient_warning = '<p class="no_recipient_warning">Aucune adresse de destination n\'a été configurée, envoi d\'e-mail impossible!</p>'; | ||
| 44 | } | ||
| 45 | |||
| 46 | ob_start(); | ||
| 47 | require $viewFile; | ||
| 48 | $this->html = ob_get_clean(); // pas de concaténation ici, on écrase | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } \ No newline at end of file | ||
