123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace Cas\Dao;
- use KIF\Dao\DBAgileDev;
- use KIF\Data\ResultWrapper;
- /**
- *
- * 活动表单数据
- */
- class LotteryEventsForms extends DBAgileDev {
- protected $tableName = 'lottery_events_forms';
-
- /**
- * 数据库里的真实字段
- * @var array
- */
- protected $other_field = array(
- 'events_id',
- 'uid',
- # 审核字段 1未审核 2审核通过 3审核不通过
- 'audit',
- );
-
- /**
- *
- * 验证表单数据
- * @param array $forms 后台定义的表单
- * @param array $formData 用户提交的表单数据
- * @return Ambigous <\KIF\Data\ResultWrapper, \KIF\Data\ResultWrapper>array
- */
- public function verifyFormData($forms, $formData) {
- if (!$forms) {
- return ResultWrapper::success();
- }
-
- foreach ($forms as $tmpForm) {
- $data = $formData[$tmpForm['name']];
- if ($tmpForm['required']) {
- if (!$data) {
- $errorMsg = $this->getErrorMsg($tmpForm['name'], $tmpForm['type']);
- return ResultWrapper::fail($errorMsg);
- }
-
- if ($tmpForm['rule']['size']) {
- if (mb_strlen($data) < $tmpForm['rule']['size']) {
- $errorMsg = $this->getErrorMsg($tmpForm['name'], $tmpForm['type']);
- return ResultWrapper::fail($errorMsg);
- }
- }
-
- if ($tmpForm['rule']['regular']) {
- if (!preg_match($tmpForm['rule']['regular'], $data)) {
- $errorMsg = $this->getErrorMsg($tmpForm['name'], $tmpForm['type']);
- return ResultWrapper::fail($errorMsg);
- }
- }
- } else {
- if (!$data) {
- continue;
- }
-
- if ($tmpForm['rule']['size']) {
- if (mb_strlen($data) < $tmpForm['rule']['size']) {
- $errorMsg = $this->getErrorMsg($tmpForm['name'], $tmpForm['type']);
- return ResultWrapper::fail($errorMsg);
- }
- }
-
- if ($tmpForm['rule']['regular']) {
- if (!preg_match($tmpForm['rule']['regular'], $data)) {
- $errorMsg = $this->getErrorMsg($tmpForm['name'], $tmpForm['type']);
- return ResultWrapper::fail($errorMsg);
- }
- }
- }
- }
-
- return ResultWrapper::success();
- }
-
- /**
- *
- * 获取表单验证的错误信息
- * @param unknown $form_name
- * @param string $form_type
- * @return boolean|string
- */
- public function getErrorMsg($form_name, $form_type = 'text') {
- if (!$form_name) {
- return false;
- }
-
- $errorMsg = '';
- switch ($form_type) {
- case 'text':
- $errorMsg = "请填写有效{$form_name}";
- break;
- case 'textarea':
- $errorMsg = "请填写有效{$form_name}";
- break;
- case 'select':
- $errorMsg = "请选择{$form_name}";
- break;
- default:
- $errorMsg = "";
- break;
- }
-
- return $errorMsg;
- }
- }
|