diff --git a/front/form.form.php b/front/form.form.php index 4bbc22441..3a3fc15d2 100644 --- a/front/form.form.php +++ b/front/form.form.php @@ -41,6 +41,7 @@ if (isset($_POST['add'])) { // Add a new Form Session::checkRight('entity', UPDATE); + $_POST['_create_empty_section'] = true; $newID = $form->add($_POST); Html::redirect(FORMCREATOR_ROOTDOC . '/front/form.form.php?id=' . $newID); diff --git a/inc/form.class.php b/inc/form.class.php index 011d1b477..5c878c90c 100644 --- a/inc/form.class.php +++ b/inc/form.class.php @@ -1332,6 +1332,13 @@ public function prepareInputForAdd($input) { * @return void */ public function post_addItem() { + if (isset($this->input['_create_empty_section'])) { + $section = new PluginFormcreatorSection(); + $section->add([ + self::getForeignKeyField() => $this->getID(), + 'name' => PluginFormcreatorSection::getTypeName(1), + ]); + } $this->updateValidators(); if ($this->input['show_rule'] != PluginFormcreatorCondition::SHOW_RULE_ALWAYS) { $this->updateConditions($this->input); diff --git a/tests/3-unit/PluginFormcreatorForm.php b/tests/3-unit/PluginFormcreatorForm.php index bd54871a7..cffbe9fd6 100644 --- a/tests/3-unit/PluginFormcreatorForm.php +++ b/tests/3-unit/PluginFormcreatorForm.php @@ -1277,4 +1277,22 @@ public function testCheckImportVersion($version, $expected) { $output = \PluginFormcreatorForm::checkImportVersion($version); $this->boolean($output)->isEqualTo($expected); } + + public function testAdd() { + $instance = $this->newTestedInstance(); + $instance->add([ + '_create_empty_section' => true, + 'name' => 'form with auto created section' + ]); + + $this->boolean($instance->isNewItem())->isFalse(); + $section = new \PluginFormcreatorSection(); + $rows = $section->find([ + 'plugin_formcreator_forms_id' => $instance->getID(), + ]); + + $this->array($rows)->hasSize(1); + $row = array_shift($rows); + $this->string($row['name'])->isEqualTo(\PluginFormcreatorSection::getTypeName(1)); + } }