示例#1
0
文件: Example.php 项目: cargomedia/cm
 public function ajax_validate(CM_Params $params, CM_Frontend_JavascriptContainer_View $handler, CM_Http_Response_View_Ajax $response)
 {
     $data = $params->getArray('data');
     $result = [];
     foreach ($data as $name => $userInput) {
         $field = $this->getField($name);
         $empty = $field->isEmpty($userInput);
         $value = null;
         $validationError = null;
         if (!$empty) {
             try {
                 $value = $field->validate($response->getEnvironment(), $userInput);
             } catch (CM_Exception_FormFieldValidation $e) {
                 $validationError = $e->getMessagePublic($response->getRender());
             }
         }
         $result[$name] = ['value' => $value, 'empty' => $empty, 'validationError' => $validationError];
     }
     return $result;
 }