Initialisation des variables de session

This commit is contained in:
Deltacms 2024-01-08 10:43:49 +01:00
parent abfe4cca2b
commit 9ba29fea30
2 changed files with 14 additions and 13 deletions

View File

@ -391,6 +391,17 @@ class form extends common {
$param = '';
$detectBot ='';
include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php');
// Création du brouillon s'il n'existe pas
if( !isset($_SESSION['draft'])){
$_SESSION['draft'] = [];
$_SESSION['draft']['mail'] = "";
$_SESSION['draft']['textarea'] = "";
$_SESSION['draft']['datetime'] = null;
$_SESSION['draft']['checkbox'] = [];
$_SESSION['draft']['select'] = [];
$_SESSION['draft']['text'] = [];
$_SESSION['draft']['file'] = "";
}
// Soumission du formulaire
if($this->isPost()) {
// $notice concerne la pièce jointe et le captcha
@ -421,16 +432,6 @@ class form extends common {
}
}
// Création du brouillon s'il n'existe pas
if( $_SESSION['draft']===[] || $_SESSION['draft']===null){
$_SESSION['draft']['mail'] = "";
$_SESSION['draft']['textarea'] = "";
$_SESSION['draft']['datetime'] = null;
$_SESSION['draft']['checkbox'] = [];
$_SESSION['draft']['select'] = [];
$_SESSION['draft']['text'] = [];
$_SESSION['draft']['file'] = "";
}
// Mise à jour du brouillon
$textIndex = 0; $selectIndex=0; $checkboxIndex=0;
for( $index = 0; $index <= count($this->getData(['module', $this->getUrl(0), 'input'])); $index++){

View File

@ -60,14 +60,14 @@ if($this->getData(['module', $this->getUrl(0), 'input'])): ?>
<?php echo template::select('formInput[' . $index . ']', $values, [
'id' => 'formInput_' . $index,
'label' => $input['name'],
'selected' => $values[$_SESSION['draft']['select'][$selectIndex]]
'selected' => isset($_SESSION['draft']['select'][$selectIndex])? $values[$_SESSION['draft']['select'][$selectIndex]] : ''
]);
$selectIndex++; ?>
<?php elseif($input['type'] === $module::TYPE_TEXT): ?>
<?php echo template::text('formInput[' . $index . ']', [
'id' => 'formInput_' . $index,
'label' => $input['name'],
'value' => $_SESSION['draft']['text'][$textIndex]
'value' => isset($_SESSION['draft']['text'][$textIndex]) ? $_SESSION['draft']['text'][$textIndex] : ''
]);
$textIndex++; ?>
<?php elseif($input['type'] === $module::TYPE_TEXTAREA): ?>
@ -86,7 +86,7 @@ if($this->getData(['module', $this->getUrl(0), 'input'])): ?>
]); ?>
<?php elseif($input['type'] === $module::TYPE_CHECKBOX):
echo template::checkbox('formInput[' . $index . ']', true, $input['name'], [
'checked' => $_SESSION['draft']['checkbox'][$checkboxIndex]
'checked' => isset($_SESSION['draft']['checkbox'][$checkboxIndex]) ? $_SESSION['draft']['checkbox'][$checkboxIndex] : false
]);
$checkboxIndex++; ?>
<?php elseif($input['type'] === $module::TYPE_FILE): ?>