Today I created a settings page with Themosis. After testing the validation rules I noticed that when the validation rules failed that WordPress stored an empty string.
Steps to reproduce
Create a hook class and add the following code block
// Customize WordPress...
use Themosis\Support\Facades\Field;
use Themosis\Support\Facades\Page;
use Themosis\Support\Section;
$page = Page::make('demo-page', 'Demo page')
->set();
$page->addSections([
new Section('general', 'General'),
]);
$page->addSettings([
'general' => [
Field::textarea('field_1', [
'rules' => 'required|min:10|max:120',
]),
],
]);
Go to the demo page and add the following text "This is a test text block" and save this setting
Change the setting to "This"
The old value "This is a test text block" will be overwritten with an empty string
Expected behavior
In my point of view, when validation rules fail, the old values should not overwrite with an empty string. Instead, the old values should don't touched. Validation should ensure that only valid values get stored. Currently, this solution seems broken.
Validation is a very common task in web applications. Data entered in forms needs to be validated. Data also needs to be
validated before it is written into a database or passed to a web service.
Description
Today I created a settings page with Themosis. After testing the validation rules I noticed that when the validation rules failed that WordPress stored an empty string.
Steps to reproduce
The old value "This is a test text block" will be overwritten with an empty string
Expected behavior
In my point of view, when validation rules fail, the old values should not overwrite with an empty string. Instead, the old values should don't touched. Validation should ensure that only valid values get stored. Currently, this solution seems broken.
Here is the "buggy" code line :)
https://github.com/themosis/framework/blob/2.0/src/Page/Page.php#L720