Skip to content

Commit 4d41965

Browse files
authored
Store form data (#342)
1 parent dbcb234 commit 4d41965

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
"require": {
2727
"php": "^8.1",
28-
"statamic/cms": "^5.17"
28+
"statamic/cms": "^5.18"
2929
},
3030
"require-dev": {
3131
"doctrine/dbal": "^3.8",

src/Forms/Form.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public static function fromModel(Model $model)
2121
->store($model->settings['store'] ?? null)
2222
->email($model->settings['email'] ?? null)
2323
->honeypot($model->settings['honeypot'] ?? null)
24+
->data($model->settings['data'] ?? [])
2425
->model($model);
2526
}
2627

@@ -39,6 +40,7 @@ public static function makeModelFromContract(Contract $source)
3940
'store' => $source->store(),
4041
'email' => $source->email(),
4142
'honeypot' => $source->honeypot(),
43+
'data' => $source->data(),
4244
],
4345
]);
4446
}

tests/Forms/FormTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPUnit\Framework\Attributes\Test;
66
use Statamic\Facades;
7+
use Statamic\Support\Arr;
78
use Tests\TestCase;
89

910
class FormTest extends TestCase
@@ -62,4 +63,12 @@ public function deleting_a_form_removes_the_blink_cache()
6263
$this->assertNull(Facades\Blink::get('eloquent-forms-test'));
6364
$this->assertNull(Facades\Blink::get('eloquent-forms'));
6465
}
66+
67+
#[Test]
68+
public function it_stores_form_data()
69+
{
70+
$form = tap(Facades\Form::make('test')->title('Test form')->data(['some' => 'data']))->save();
71+
72+
$this->assertSame(['some' => 'data'], Arr::get($form->model(), 'settings.data'));
73+
}
6574
}

0 commit comments

Comments
 (0)