brouillon de Form avec variables de session

This commit is contained in:
Deltacms 2024-01-08 08:18:17 +01:00
parent 2b82f5c4a5
commit 54f120fd27
2 changed files with 22 additions and 38 deletions

View File

@ -422,57 +422,49 @@ class form extends common {
} }
// Création du brouillon s'il n'existe pas // Création du brouillon s'il n'existe pas
if( $this->getData(['module', $this->getUrl(0), 'draft']) === "" ){ if( $_SESSION['draft']===[] || $_SESSION['draft']===null){
$this->setData([ $_SESSION['draft']['mail'] = "";
'module', $_SESSION['draft']['textarea'] = "";
$this->getUrl(0), $_SESSION['draft']['datetime'] = null;
'draft', $_SESSION['draft']['checkbox'] = [];
[ $_SESSION['draft']['select'] = [];
'mail' => "", $_SESSION['draft']['text'] = [];
'textarea' => "", $_SESSION['draft']['file'] = "";
'datetime' => null,
'checkbox' => false,
'select' => "",
'text' => "",
'file' =>""
]
]);
} }
// Mise à jour du brouillon // Mise à jour du brouillon
$textIndex = 0; $selectIndex=0; $checkboxIndex=0; $textIndex = 0; $selectIndex=0; $checkboxIndex=0;
for( $index = 0; $index <= count($this->getData(['module', $this->getUrl(0), 'input'])); $index++){ for( $index = 0; $index <= count($this->getData(['module', $this->getUrl(0), 'input'])); $index++){
switch ($this->getData(['module', $this->getUrl(0), 'input', $index, 'type'])){ switch ($this->getData(['module', $this->getUrl(0), 'input', $index, 'type'])){
case self::TYPE_MAIL: case self::TYPE_MAIL:
$this->setData(['module', $this->getUrl(0), 'draft', 'mail', $this->getInput('formInput[' . $index . ']',helper::FILTER_MAIL)]); $_SESSION['draft']['mail'] = $this->getInput('formInput[' . $index . ']',helper::FILTER_MAIL);
break; break;
case self::TYPE_TEXTAREA: case self::TYPE_TEXTAREA:
$this->setData(['module', $this->getUrl(0), 'draft', 'textarea', $this->getInput('formInput[' . $index . ']',helper::FILTER_STRING_LONG_NOSTRIP)]); $_SESSION['draft']['textarea'] = $this->getInput('formInput[' . $index . ']',helper::FILTER_STRING_LONG_NOSTRIP);
break; break;
case self::TYPE_DATETIME: case self::TYPE_DATETIME:
$dateTime = time(); $dateTime = time();
if( $this->getInput('formInput[' . $index . ']') !== "" && $this->getInput('formInput[' . $index . ']') !== null) $dateTime = $this->getInput('formInput[' . $index . ']',helper::FILTER_DATETIME, true); if( $this->getInput('formInput[' . $index . ']') !== "" && $this->getInput('formInput[' . $index . ']') !== null) $dateTime = $this->getInput('formInput[' . $index . ']',helper::FILTER_DATETIME, true);
$this->setData(['module', $this->getUrl(0), 'draft', 'datetime', $dateTime]); $_SESSION['draft']['datetime'] = $dateTime;
break; break;
case self::TYPE_CHECKBOX: case self::TYPE_CHECKBOX:
$this->setData(['module', $this->getUrl(0), 'draft', 'checkbox', $checkboxIndex, $this->getInput('formInput[' . $index . ']',helper::FILTER_BOOLEAN)]); $_SESSION['draft']['checkbox'][$checkboxIndex] = $this->getInput('formInput[' . $index . ']',helper::FILTER_BOOLEAN);
$checkboxIndex++; $checkboxIndex++;
break; break;
case self::TYPE_SELECT: case self::TYPE_SELECT:
$this->setData(['module', $this->getUrl(0), 'draft', 'select', $selectIndex, $this->getInput('formInput[' . $index . ']')]); $_SESSION['draft']['select'][$selectIndex] = $this->getInput('formInput[' . $index . ']');
$selectIndex++; $selectIndex++;
break; break;
case self::TYPE_TEXT: case self::TYPE_TEXT:
$this->setData(['module', $this->getUrl(0), 'draft', 'text', $textIndex, $this->getInput('formInput[' . $index . ']')]); $_SESSION['draft']['text'][$textIndex] = $this->getInput('formInput[' . $index . ']');
$textIndex++; $textIndex++;
break; break;
case self::TYPE_FILE: case self::TYPE_FILE:
$this->setData(['module', $this->getUrl(0), 'draft', 'file', basename($_FILES["fileToUpload"]["name"]) ]); $_SESSION['draft']['file'] = basename($_FILES["fileToUpload"]["name"]);
break; break;
default: default:
$filter = helper::FILTER_STRING_SHORT; $filter = helper::FILTER_STRING_SHORT;
} }
} }
$this->setData(['module', $this->getUrl(0), 'draft', 'draftTime', time() ]);
// Préparation du contenu du mail // Préparation du contenu du mail
$data = []; $data = [];
@ -637,7 +629,7 @@ class form extends common {
$redirect = helper::baseUrl() . $this->getUrl(0); $redirect = helper::baseUrl() . $this->getUrl(0);
if ( $this->getData(['module', $this->getUrl(0), 'config', 'pageId']) !== '') $redirect = helper::baseUrl() . $this->getData(['module', $this->getUrl(0), 'config', 'pageId']); if ( $this->getData(['module', $this->getUrl(0), 'config', 'pageId']) !== '') $redirect = helper::baseUrl() . $this->getData(['module', $this->getUrl(0), 'config', 'pageId']);
// Effacement des données provisoires // Effacement des données provisoires
$this->setData(['module', $this->getUrl(0), 'draft', '']); if( self::$inputNotices === [] )$_SESSION['draft']=[];
} else { } else {
$sent = false; $sent = false;
} }
@ -658,13 +650,6 @@ class form extends common {
]); ]);
} }
// Effacement des données provisoires trop anciennes
if( null !== $this->getData(['module', $this->getUrl(0), 'draft', 'draftTime']) && ($this->getData(['module', $this->getUrl(0), 'draft', 'draftTime']) + 300) < time() ){
$this->setData(['module', $this->getUrl(0), 'draft', '']);
$this->addOutput([
'redirect' => helper::baseUrl() . $this->getUrl(0)
]);
}
// Valeurs en sortie // Valeurs en sortie
$this->addOutput([ $this->addOutput([
'showBarEditButton' => true, 'showBarEditButton' => true,

View File

@ -48,7 +48,7 @@ if($this->getData(['module', $this->getUrl(0), 'input'])): ?>
<?php echo template::mail('formInput[' . $index . ']', [ <?php echo template::mail('formInput[' . $index . ']', [
'id' => 'formInput_' . $index, 'id' => 'formInput_' . $index,
'label' => $input['name'], 'label' => $input['name'],
'value' => $this->getData([ 'module', $this->getUrl(0), 'draft', 'mail']) 'value' => $_SESSION['draft']['mail']
]); ?> ]); ?>
<?php elseif($input['type'] === $module::TYPE_SELECT): ?> <?php elseif($input['type'] === $module::TYPE_SELECT): ?>
<?php <?php
@ -60,21 +60,21 @@ if($this->getData(['module', $this->getUrl(0), 'input'])): ?>
<?php echo template::select('formInput[' . $index . ']', $values, [ <?php echo template::select('formInput[' . $index . ']', $values, [
'id' => 'formInput_' . $index, 'id' => 'formInput_' . $index,
'label' => $input['name'], 'label' => $input['name'],
'selected' => $values[$this->getData([ 'module', $this->getUrl(0), 'draft', 'select', $selectIndex])] 'selected' => $values[$_SESSION['draft']['select'][$selectIndex]]
]); ]);
$selectIndex++; ?> $selectIndex++; ?>
<?php elseif($input['type'] === $module::TYPE_TEXT): ?> <?php elseif($input['type'] === $module::TYPE_TEXT): ?>
<?php echo template::text('formInput[' . $index . ']', [ <?php echo template::text('formInput[' . $index . ']', [
'id' => 'formInput_' . $index, 'id' => 'formInput_' . $index,
'label' => $input['name'], 'label' => $input['name'],
'value' => $this->getData([ 'module', $this->getUrl(0), 'draft', 'text', $textIndex]) 'value' => $_SESSION['draft']['text'][$textIndex]
]); ]);
$textIndex++; ?> $textIndex++; ?>
<?php elseif($input['type'] === $module::TYPE_TEXTAREA): ?> <?php elseif($input['type'] === $module::TYPE_TEXTAREA): ?>
<?php echo template::textarea('formInput[' . $index . ']', [ <?php echo template::textarea('formInput[' . $index . ']', [
'id' => 'formInput_' . $index, 'id' => 'formInput_' . $index,
'label' => $input['name'], 'label' => $input['name'],
'value' => $this->getData([ 'module', $this->getUrl(0), 'draft', 'textarea']), 'value' => $_SESSION['draft']['textarea'],
'class' => 'editorWysiwygComment', 'class' => 'editorWysiwygComment',
'noDirty' => true 'noDirty' => true
]); ?> ]); ?>
@ -82,12 +82,11 @@ if($this->getData(['module', $this->getUrl(0), 'input'])): ?>
<?php echo template::date('formInput[' . $index . ']', [ <?php echo template::date('formInput[' . $index . ']', [
'id' => 'formInput_' . $index, 'id' => 'formInput_' . $index,
'label' => $input['name'], 'label' => $input['name'],
'value' => $this->getData([ 'module', $this->getUrl(0), 'draft', 'datetime']) 'value' => $_SESSION['draft']['datetime']
]); ?> ]); ?>
<?php elseif($input['type'] === $module::TYPE_CHECKBOX): <?php elseif($input['type'] === $module::TYPE_CHECKBOX):
echo template::checkbox('formInput[' . $index . ']', true, $input['name'], [ echo template::checkbox('formInput[' . $index . ']', true, $input['name'], [
'before' => false, 'checked' => $_SESSION['draft']['checkbox'][$checkboxIndex]
'checked' => false // Problème non solutionné avec $this->getData([ 'module', $this->getUrl(0), 'draft', 'checkbox', $checkboxIndex])
]); ]);
$checkboxIndex++; ?> $checkboxIndex++; ?>
<?php elseif($input['type'] === $module::TYPE_FILE): ?> <?php elseif($input['type'] === $module::TYPE_FILE): ?>