コード例 #1
0
 /**
  * Submit the form and its data to the API and process the response
  * @param array $arr_form_data
  */
 public function submitForm(array $arr_form_data)
 {
     //check which form type has been received
     switch ($this->objFormData->form_types_behaviour) {
         default:
             $api_url = $this->api_url . "/forms/external/" . $this->objFormData->id;
             $this->objApiRequest->setKey("api_url", $api_url);
             $objResult = $this->objApiRequest->performCreateAction($arr_form_data, array("fid" => $this->objFormData->id));
             //process response
             if ($objResult->HTTP_RESPONSE_CODE != 200) {
                 //extract message
                 $arr_t = explode(":", $objResult->HTTP_RESPONSE_MESSAGE);
                 $this->form_messages[] = array_pop($arr_t);
                 //add errors to elements
                 foreach ($this->arr_form_elements as $objField) {
                     foreach ($objResult->data as $objFieldResponse) {
                         if (!isset($objFieldResponse->attributes)) {
                             continue;
                         }
                         //end if
                         if (!isset($objFieldResponse->attributes->name) || !is_object($objFieldResponse) || $objFieldResponse->attributes->name != $objField->name) {
                             continue;
                         }
                         //end if
                         //set error message
                         if (isset($objFieldResponse->messages) && count($objFieldResponse->messages) > 0) {
                             $objField->setErrors((object) $objFieldResponse->messages);
                         }
                         //end if
                     }
                     //end foreach
                 }
                 //end foreach
             } else {
                 $this->form_messages[] = "Form has been submitted";
             }
             //end if
             break;
     }
     //end switch
 }