Skip to content

Commit 3509a24

Browse files
committed
优化:前端表单提交字段类型数组自动转换检测
1 parent 81d7905 commit 3509a24

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

module/Cms/Docs/release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- 新增:CMS备份和恢复增加备份配置选项,支持多主题快速切换
88
- 优化:系统响应默认处理函数优化处理方式
99
- 优化:CMS自定义字段编辑标识每次刷新问题
10+
- 优化:前端表单提交字段类型数组自动转换检测
1011
- 修复:CMS 自定义字段显示异常问题修复
1112

1213
---

module/Cms/Field/AbstractCmsField.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ public function prepareInputOrFail($field, InputPackage $input)
3737
return $input->getTrimString($field['name']);
3838
}
3939

40+
protected function prepareInputArrayAutoDetect($field, InputPackage $input)
41+
{
42+
$value = $input->get($field['name']);
43+
if (is_string($value)) {
44+
$value = @json_decode($value, true);
45+
if (empty($value)) {
46+
$value = [];
47+
}
48+
$input->set($field['name'], $value);
49+
}
50+
}
51+
4052
/**
4153
* 用户输入字段检查
4254
* @param $field

module/Cms/Field/CheckboxCmsField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function prepareDataOrFail($data)
3636

3737
public function prepareInputOrFail($field, InputPackage $input)
3838
{
39+
$this->prepareInputArrayAutoDetect($field, $input);
3940
return $input->getArray($field['name']);
4041
}
4142

module/Cms/Field/ImagesCmsField.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function prepareDataOrFail($data)
3030

3131
public function prepareInputOrFail($field, InputPackage $input)
3232
{
33+
$this->prepareInputArrayAutoDetect($field, $input);
3334
return $input->getImagesPath($field['name']);
3435
}
3536

0 commit comments

Comments
 (0)