From 54f120fd273e0b00bc941cbca8aeaa2959d97ce5 Mon Sep 17 00:00:00 2001 From: Deltacms Date: Mon, 8 Jan 2024 08:18:17 +0100 Subject: [PATCH] brouillon de Form avec variables de session --- module/form/form.php | 47 +++++++++++--------------------- module/form/view/index/index.php | 13 ++++----- 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/module/form/form.php b/module/form/form.php index db32d4e..309eb62 100644 --- a/module/form/form.php +++ b/module/form/form.php @@ -422,57 +422,49 @@ class form extends common { } // Création du brouillon s'il n'existe pas - if( $this->getData(['module', $this->getUrl(0), 'draft']) === "" ){ - $this->setData([ - 'module', - $this->getUrl(0), - 'draft', - [ - 'mail' => "", - 'textarea' => "", - 'datetime' => null, - 'checkbox' => false, - 'select' => "", - 'text' => "", - 'file' =>"" - ] - ]); + 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++){ switch ($this->getData(['module', $this->getUrl(0), 'input', $index, 'type'])){ 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; 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; case self::TYPE_DATETIME: $dateTime = time(); 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; 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++; break; 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++; break; 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++; break; case self::TYPE_FILE: - $this->setData(['module', $this->getUrl(0), 'draft', 'file', basename($_FILES["fileToUpload"]["name"]) ]); + $_SESSION['draft']['file'] = basename($_FILES["fileToUpload"]["name"]); break; default: $filter = helper::FILTER_STRING_SHORT; } } - $this->setData(['module', $this->getUrl(0), 'draft', 'draftTime', time() ]); // Préparation du contenu du mail $data = []; @@ -637,7 +629,7 @@ class form extends common { $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']); // Effacement des données provisoires - $this->setData(['module', $this->getUrl(0), 'draft', '']); + if( self::$inputNotices === [] )$_SESSION['draft']=[]; } else { $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 $this->addOutput([ 'showBarEditButton' => true, diff --git a/module/form/view/index/index.php b/module/form/view/index/index.php index 3ee09b1..e3c8c63 100644 --- a/module/form/view/index/index.php +++ b/module/form/view/index/index.php @@ -48,7 +48,7 @@ if($this->getData(['module', $this->getUrl(0), 'input'])): ?> 'formInput_' . $index, 'label' => $input['name'], - 'value' => $this->getData([ 'module', $this->getUrl(0), 'draft', 'mail']) + 'value' => $_SESSION['draft']['mail'] ]); ?> getData(['module', $this->getUrl(0), 'input'])): ?> 'formInput_' . $index, 'label' => $input['name'], - 'selected' => $values[$this->getData([ 'module', $this->getUrl(0), 'draft', 'select', $selectIndex])] + 'selected' => $values[$_SESSION['draft']['select'][$selectIndex]] ]); $selectIndex++; ?> 'formInput_' . $index, 'label' => $input['name'], - 'value' => $this->getData([ 'module', $this->getUrl(0), 'draft', 'text', $textIndex]) + 'value' => $_SESSION['draft']['text'][$textIndex] ]); $textIndex++; ?> 'formInput_' . $index, 'label' => $input['name'], - 'value' => $this->getData([ 'module', $this->getUrl(0), 'draft', 'textarea']), + 'value' => $_SESSION['draft']['textarea'], 'class' => 'editorWysiwygComment', 'noDirty' => true ]); ?> @@ -82,12 +82,11 @@ if($this->getData(['module', $this->getUrl(0), 'input'])): ?> 'formInput_' . $index, 'label' => $input['name'], - 'value' => $this->getData([ 'module', $this->getUrl(0), 'draft', 'datetime']) + 'value' => $_SESSION['draft']['datetime'] ]); ?> false, - 'checked' => false // Problème non solutionné avec $this->getData([ 'module', $this->getUrl(0), 'draft', 'checkbox', $checkboxIndex]) + 'checked' => $_SESSION['draft']['checkbox'][$checkboxIndex] ]); $checkboxIndex++; ?>