Browse Source

信息表单收集提交表单优化

master
wanghongjun 2 years ago
parent
commit
b03e371e88
  1. 26
      addons/weliam_smartcity/api/Enroll.php

26
addons/weliam_smartcity/api/Enroll.php

@ -44,21 +44,14 @@ class EnrollModuleUniapp extends Uniapp
$form_data = $_GPC['form_data'];
$template_type = $_GPC['template_type'];
$activities_id = $_GPC['activities_id'];
$enroll_data = $_GPC['enroll_data'];
$enroll_data = [];
if (empty($diyformid) || !is_numeric($diyformid)) throw new Exception('表单id不能为空');
if (empty($form_data)) throw new Exception('表单数据不能为空');
if (empty($enroll_data)) throw new Exception('表单填写数据不能为空');
if (empty($template_type)) throw new Exception('模板类型不能为空');
if (!in_array($template_type,array_keys(FormTemplate::$template_type))) throw new Exception('模板类型数据错误');
if (empty($activities_id) || !is_numeric($activities_id)) throw new Exception('活动id不能为空');
$enroll_data = json_decode(html_entity_decode($enroll_data),true);
foreach ($enroll_data as $item) {
if (!isset($item['name'])) throw new Exception('表单填写数据字段不能为空');
if (!isset($item['value'])) throw new Exception('表单填写数据值不能为空');
}
$activitiesData = FormTemplate::getTemplateTableData($template_type,$activities_id);
if (empty($activitiesData)) throw new Exception('该活动不存在');
@ -66,7 +59,22 @@ class EnrollModuleUniapp extends Uniapp
if ($query) throw new Exception('已报名该活动');
$diyFormInfo = html_entity_decode($form_data);
$diyFormInfo = base64_encode($diyFormInfo);
$diyFormInfo = json_decode($diyFormInfo,true);
foreach ($diyFormInfo as $info) {
if ($info['is_required'] == '1') {
if (empty($info['data'])) throw new Exception($info['title'] . " 为必填项");
}
$enroll_data[] = [
'name' => $info['title'],
'value' => $info['data']
];
}
if (empty($enroll_data)) throw new Exception('请填写至少一项');
$diyform = pdo_get(PDO_NAME . 'diyform',['id' => $diyformid],'info');
if (empty($diyform)) throw new Exception('表单id错误');
$diyFormInfo = $diyform['info'];
// 开启事务
pdo_begin();

Loading…
Cancel
Save