Add re-populate form on submission error

This commit is contained in:
osaajani 2020-08-17 21:05:01 +02:00
parent d52db2e1d2
commit 7277f1e98d
11 changed files with 44 additions and 29 deletions

View File

@ -121,7 +121,7 @@ namespace controllers\publics;
if (!$this->internal_webhook->create($_SESSION['user']['id'], $url, $type)) if (!$this->internal_webhook->create($_SESSION['user']['id'], $url, $type))
{ {
\FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce webhook.'); \FlashMessage\FlashMessage::push('danger', 'Impossible de créer ce webhook, vérifiez qu\'il s\'agit bien d\'une URL HTTP(S) valide.');
return $this->redirect(\descartes\Router::url('Webhook', 'add')); return $this->redirect(\descartes\Router::url('Webhook', 'add'));
} }

View File

@ -13,6 +13,10 @@
$_SESSION['csrf'] = str_shuffle(uniqid().uniqid()); $_SESSION['csrf'] = str_shuffle(uniqid().uniqid());
} }
//Save previous $_POST for re-populate forms on validation errors
$_SESSION['previous_http_post'] = $_SESSION['http_post'] ?? [];
$_SESSION['http_post'] = $_POST;
//Routing current query //Routing current query
try try
{ {

View File

@ -41,21 +41,21 @@
<div class="form-group"> <div class="form-group">
<label>Nom commande</label> <label>Nom commande</label>
<div class="form-group"> <div class="form-group">
<input name="name" class="form-control" type="text" placeholder="Nom commande" autofocus required> <input name="name" class="form-control" type="text" placeholder="Nom commande" autofocus required value="<?php $this->s($_SESSION['previous_http_post']['name'] ?? '') ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Commande à appeler (la commande sera appelée depuis le dossier "<?php echo PWD_SCRIPTS; ?>")</label> <label>Commande à appeler (la commande sera appelée depuis le dossier "<?php echo PWD_SCRIPTS; ?>")</label>
<div class="form-group input-group"> <div class="form-group input-group">
<span class="input-group-addon"><span class="fa fa-link"></span></span> <span class="input-group-addon"><span class="fa fa-link"></span></span>
<input name="script" class="form-control" type="text" placeholder="Ex : chauffage/monter.sh" autofocus required> <input name="script" class="form-control" type="text" placeholder="Ex : chauffage/monter.sh" autofocus required value="<?php $this->s($_SESSION['previous_http_post']['script'] ?? ''); ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Niveau administrateur obligatoire</label> <label>Niveau administrateur obligatoire</label>
<div class="form-group"> <div class="form-group">
<input name="admin" type="radio" value="1" required /> Oui <input name="admin" type="radio" value="1" required <?= (isset($_SESSION['previous_http_post']['admin']) && (bool) $_SESSION['previous_http_post']['admin']) ? 'checked' : ''; ?>/> Oui
<input name="admin" type="radio" value="0" required /> Non <input name="admin" type="radio" value="0" required <?= (isset($_SESSION['previous_http_post']['admin']) && !(bool) $_SESSION['previous_http_post']['admin']) ? '' : 'checked'; ?>/> Non
</div> </div>
</div> </div>
<a class="btn btn-danger" href="<?php echo \descartes\Router::url('Command', 'list'); ?>">Annuler</a> <a class="btn btn-danger" href="<?php echo \descartes\Router::url('Command', 'list'); ?>">Annuler</a>

View File

@ -42,7 +42,7 @@
<label>Nom du groupe conditionnel</label> <label>Nom du groupe conditionnel</label>
<div class="form-group input-group"> <div class="form-group input-group">
<span class="input-group-addon"><span class="fa fa-users"></span></span> <span class="input-group-addon"><span class="fa fa-users"></span></span>
<input name="name" class="form-control" type="text" placeholder="Nom groupe" autofocus required> <input name="name" class="form-control" type="text" placeholder="Nom groupe" autofocus required value="<?php $this->s($_SESSION['previous_http_post']['name'] ?? '') ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -51,7 +51,7 @@
Les conditions vous permettent de définir dynamiquement les contacts qui appartiennent au groupe en utilisant leurs données additionnelles. Pour plus d'informations consultez la documentation relative à <a href="#">l'utilisation des groupes conditionnels.</a><br/> Les conditions vous permettent de définir dynamiquement les contacts qui appartiennent au groupe en utilisant leurs données additionnelles. Pour plus d'informations consultez la documentation relative à <a href="#">l'utilisation des groupes conditionnels.</a><br/>
Vous pouvez prévisualiser les contacts qui feront parti du groupe en cliquant sur le bouton <b>"Prévisualiser les contacts"</b>. Vous pouvez prévisualiser les contacts qui feront parti du groupe en cliquant sur le bouton <b>"Prévisualiser les contacts"</b>.
</p> </p>
<input class="form-control" name="condition" placeholder="Ex : contact.datas.gender == 'male'"/> <input class="form-control" name="condition" placeholder="Ex : contact.gender == 'male'" value="<?php $this->s($_SESSION['previous_http_post']['condition'] ?? '') ?>"/>
<div class="scheduled-preview-container"> <div class="scheduled-preview-container">
<a class="btn btn-info preview-button" href="#">Prévisualiser les contacts</a> <a class="btn btn-info preview-button" href="#">Prévisualiser les contacts</a>
</div> </div>

View File

@ -42,13 +42,13 @@
<label>Nom contact</label> <label>Nom contact</label>
<div class="form-group input-group"> <div class="form-group input-group">
<span class="input-group-addon"><span class="fa fa-user"></span></span> <span class="input-group-addon"><span class="fa fa-user"></span></span>
<input name="name" class="form-control" type="text" placeholder="Nom contact" autofocus required> <input name="name" class="form-control" type="text" placeholder="Nom contact" autofocus required value="<?php $this->s($_SESSION['previous_http_post']['name'] ?? '') ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Numéro de téléphone du contact</label> <label>Numéro de téléphone du contact</label>
<div class="form-group"> <div class="form-group">
<input name="" class="form-control" type="tel" id="phone-international-input"> <input name="" class="form-control" type="tel" id="phone-international-input" value="<?php $this->s($_SESSION['previous_http_post']['number'] ?? '') ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -58,6 +58,16 @@
Laissez vide si vous ne souhaitez pas renseigner d'informations supplémentaires pour le contact. Utilisez uniquement des lettres, des chiffres et des underscore pour les noms de données, ni espace ni caractères spéciaux. Laissez vide si vous ne souhaitez pas renseigner d'informations supplémentaires pour le contact. Utilisez uniquement des lettres, des chiffres et des underscore pour les noms de données, ni espace ni caractères spéciaux.
</p> </p>
<div class="contact-datas-container"> <div class="contact-datas-container">
<?php foreach ($_SESSION['previous_http_post']['datas'] ?? [] as $key => $value) { ?>
<?php if ($value == null) { continue; } ?>
<div class="form-group">
<input name="" class="form-control contact-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*" value="<?php $this->s($key) ?>">
:
<input name="" class="form-control contact-data-value" type="text" placeholder="Valeur de la donnée" value="<?php $this->s($value) ?>">
<a href="#" class="contact-datas-remove"><span class="fa fa-times"></span></a>
</div>
<?php } ?>
<div class="form-group"> <div class="form-group">
<input name="" class="form-control contact-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*"> <input name="" class="form-control contact-data-name" type="text" placeholder="Nom de la donnée" pattern="[a-zA-Z0-9_]*">
: :

View File

@ -42,12 +42,12 @@
<label>Nom du groupe</label> <label>Nom du groupe</label>
<div class="form-group input-group"> <div class="form-group input-group">
<span class="input-group-addon"><span class="fa fa-users"></span></span> <span class="input-group-addon"><span class="fa fa-users"></span></span>
<input name="name" class="form-control" type="text" placeholder="Nom groupe" autofocus required> <input name="name" class="form-control" type="text" placeholder="Nom groupe" autofocus required value="<?php $this->s($_SESSION['previous_http_post']['name'] ?? '') ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Contacts du groupe</label> <label>Contacts du groupe</label>
<input class="add-contacts form-control" name="contacts[]"/> <input class="add-contacts form-control" name="contacts[]" value="<?php $this->s(json_encode($_SESSION['previous_http_post']['contacts'] ?? [])); ?>"/>
</div> </div>
<a class="btn btn-danger" href="<?php echo \descartes\Router::url('Group', 'list'); ?>">Annuler</a> <a class="btn btn-danger" href="<?php echo \descartes\Router::url('Group', 'list'); ?>">Annuler</a>
<input type="submit" class="btn btn-success" value="Enregistrer le groupe" /> <input type="submit" class="btn btn-success" value="Enregistrer le groupe" />

View File

@ -44,7 +44,7 @@
Le nom du téléphone qui enverra et recevra les messages. Le nom du téléphone qui enverra et recevra les messages.
</p> </p>
<div class="form-group"> <div class="form-group">
<input required="required" name="name" class="form-control" placeholder="Nom du téléphone"> <input required="required" name="name" class="form-control" placeholder="Nom du téléphone" value="<?php $this->s($_SESSION['previous_http_post']['name'] ?? '') ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -58,6 +58,7 @@
value="<?= $adapter['meta_classname'] ?>" value="<?= $adapter['meta_classname'] ?>"
data-description="<?php $this->s($adapter['meta_description']); ?>" data-description="<?php $this->s($adapter['meta_description']); ?>"
data-datas-fields="<?php $this->s(json_encode($adapter['meta_datas_fields'])); ?>" data-datas-fields="<?php $this->s(json_encode($adapter['meta_datas_fields'])); ?>"
<?= ($_SESSION['previous_http_post']['adapter'] ?? '') == $adapter['meta_classname'] ? 'selected' : '' ?>
> >
<?php $this->s($adapter['meta_name']); ?> <?php $this->s($adapter['meta_name']); ?>
</option> </option>

View File

@ -5,7 +5,7 @@
?> ?>
<div id="wrapper"> <div id="wrapper">
<?php <?php
$this->render('incs/nav', ['page' => 'phone']) $this->render('incs/nav', ['page' => 'phones'])
?> ?>
<div id="page-wrapper"> <div id="page-wrapper">
<div class="container-fluid"> <div class="container-fluid">

View File

@ -49,7 +49,7 @@
Vous pouvez obtenir une prévisualisation du résultat pour un contact en cliquant sur le boutton <b>"Prévisualiser"</b>. Vous pouvez obtenir une prévisualisation du résultat pour un contact en cliquant sur le boutton <b>"Prévisualiser"</b>.
</p> </p>
<?php } ?> <?php } ?>
<textarea name="text" class="form-control" required></textarea> <textarea name="text" class="form-control" required><?php $this->s($_SESSION['previous_http_post']['text'] ?? '') ?></textarea>
<?php if ($_SESSION['user']['settings']['templating']) { ?> <?php if ($_SESSION['user']['settings']['templating']) { ?>
<div class="scheduled-preview-container"> <div class="scheduled-preview-container">
<label>Prévisualiser pour : </label> <label>Prévisualiser pour : </label>
@ -74,7 +74,7 @@
<?php } ?> <?php } ?>
<div class="form-group"> <div class="form-group">
<label>Date d'envoi du SMS</label> <label>Date d'envoi du SMS</label>
<input name="at" class="form-control form-datetime auto-width" type="text" value="<?php $this->s($now); ?>" readonly> <input name="at" class="form-control form-datetime auto-width" type="text" readonly value="<?php $this->s($_SESSION['previous_http_post']['at'] ?? $now) ?>">
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Numéros cibles</label> <label>Numéros cibles</label>
@ -88,24 +88,24 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Contacts cibles</label> <label>Contacts cibles</label>
<input class="add-contacts form-control" name="contacts[]" value="<?php $this->s(json_encode($prefilled_contacts)); ?>" /> <input class="add-contacts form-control" name="contacts[]" value="<?php $this->s(json_encode($_SESSION['previous_http_post']['contacts'] ?? $prefilled_contacts)) ?>" />
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Groupes cibles</label> <label>Groupes cibles</label>
<input class="add-groupes form-control" name="groups[]" value="<?php $this->s(json_encode($prefilled_groups)); ?>" /> <input class="add-groupes form-control" name="groups[]" value="<?php $this->s(json_encode($_SESSION['previous_http_post']['groups'] ?? $prefilled_groups)) ?>" />
</div> </div>
<?php if ($_SESSION['user']['settings']['conditional_group'] ?? false) { ?> <?php if ($_SESSION['user']['settings']['conditional_group'] ?? false) { ?>
<div class="form-group"> <div class="form-group">
<label>Groupes conditionnels cibles</label> <label>Groupes conditionnels cibles</label>
<input class="add-conditional-groups form-control" name="conditional_groups[]" value="<?php $this->s(json_encode($prefilled_conditional_groups)); ?>"/> <input class="add-conditional-groups form-control" name="conditional_groups[]" value="<?php $this->s(json_encode($_SESSION['previous_http_post']['conditional_groups'] ?? $prefilled_conditional_groups)) ?>" />
</div> </div>
<?php } ?> <?php } ?>
<?php if ($_SESSION['user']['settings']['sms_flash']) { ?> <?php if ($_SESSION['user']['settings']['sms_flash']) { ?>
<div class="form-group"> <div class="form-group">
<label>Envoyer comme un SMS Flash : </label> <label>Envoyer comme un SMS Flash : </label>
<div class="form-group"> <div class="form-group">
<input name="flash" type="radio" value="1" required /> Oui <input name="flash" type="radio" value="1" required <?= (isset($_SESSION['previous_http_post']['flash']) && (bool) $_SESSION['previous_http_post']['flash']) ? 'checked' : ''; ?>/> Oui
<input name="flash" type="radio" value="0" required checked/> Non <input name="flash" type="radio" value="0" required <?= (!isset($_SESSION['previous_http_post']['flash']) || (isset($_SESSION['previous_http_post']['flash']) && !(bool) $_SESSION['previous_http_post']['flash'])) ? 'checked' : ''; ?>/> Non
</div> </div>
</div> </div>
<?php } ?> <?php } ?>
@ -115,7 +115,7 @@
<select name="id_phone" class="form-control"> <select name="id_phone" class="form-control">
<option value="">N'importe lequel</option> <option value="">N'importe lequel</option>
<?php foreach ($phones as $phone) { ?> <?php foreach ($phones as $phone) { ?>
<option value="<?php $this->s($phone['id']); ?>"><?php $this->s($phone['name']); ?></option> <option value="<?php $this->s($phone['id']); ?>" <?= ($_SESSION['previous_http_post']['id_phone'] ?? '') == $phone['id'] ? 'selected' : '' ?>><?php $this->s($phone['name']); ?></option>
<?php } ?> <?php } ?>
</select> </select>
</div> </div>

View File

@ -42,7 +42,7 @@
<label>Adresse e-mail</label> <label>Adresse e-mail</label>
<div class="form-group input-group"> <div class="form-group input-group">
<span class="input-group-addon"><span class="fa fa-at"></span></span> <span class="input-group-addon"><span class="fa fa-at"></span></span>
<input name="email" class="form-control" type="email" placeholder="Adresse e-mail de l'utilisateur" autofocus required> <input name="email" class="form-control" type="email" placeholder="Adresse e-mail de l'utilisateur" autofocus required value="<?php $this->s($_SESSION['previous_http_post']['email'] ?? '') ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -56,8 +56,8 @@
<div class="form-group"> <div class="form-group">
<label>Niveau administrateur : </label> <label>Niveau administrateur : </label>
<div class="form-group"> <div class="form-group">
<input name="admin" type="radio" value="1" required /> Oui <input name="admin" type="radio" value="1" required <?= (isset($_SESSION['previous_http_post']['admin']) && (bool) $_SESSION['previous_http_post']['admin']) ? 'checked' : ''; ?>/> Oui
<input name="admin" type="radio" value="0" required /> Non <input name="admin" type="radio" value="0" required <?= (isset($_SESSION['previous_http_post']['admin']) && !(bool) $_SESSION['previous_http_post']['admin']) ? 'checked' : ''; ?>/> Non
</div> </div>
</div> </div>
<?php } ?> <?php } ?>

View File

@ -39,14 +39,14 @@
<div class="form-group"> <div class="form-group">
<label>URL cible</label> <label>URL cible</label>
<div class="form-group"> <div class="form-group">
<input name="url" class="form-control" type="text" placeholder="http://example.fr/webhook/" autofocus required> <input name="url" class="form-control" type="text" placeholder="http://example.fr/webhook/" autofocus required value="<?php $this->s($_SESSION['previous_http_post']['url'] ?? '') ?>">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>Type de Webhook</label> <label>Type de Webhook</label>
<select name="type" class="form-control" required> <select name="type" class="form-control" required>
<option value="receive_sms">Réception d'un SMS</option> <option value="receive_sms" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'receive_sms' ? 'selected' : '' ?>>Réception d'un SMS</option>
<option value="send_sms">Envoi d'un SMS</option> <option value="send_sms" <?= ($_SESSION['previous_http_post']['type'] ?? '') == 'send_sms' ? 'selected' : '' ?>>Envoi d'un SMS</option>
</select> </select>
</div> </div>
<a class="btn btn-danger" href="<?php echo \descartes\Router::url('Webhook', 'list'); ?>">Annuler</a> <a class="btn btn-danger" href="<?php echo \descartes\Router::url('Webhook', 'list'); ?>">Annuler</a>