Exemplo n.º 1
0
 /**
  * The method process the submitted form and save all the form fields except captcha field.
  */
 public function processFormSubmit($form)
 {
     $date = DateUtil::getDateTime();
     $attributes = parent::getFormAttributes();
     $fields = $attributes['fields'];
     $attribs = [];
     $user = Yii::$app->user->getIdentity();
     $formSubmit = new FormSubmit();
     $formSubmit->formId = $form->id;
     $formSubmit->submittedAt = $date;
     if (isset($user)) {
         $formSubmit->submittedBy = $user->id;
     }
     // Collect fields to save in json format
     foreach ($fields as $field) {
         $fieldName = $field->name;
         // Convert CheckBox array to csv
         if ($field->isCheckboxGroup()) {
             $this->{$fieldName} = join(",", $this->{$fieldName});
         }
         if ($field->compress) {
             $attribs[$field->name] = $this->{$fieldName};
         }
     }
     $formSubmit->data = json_encode($attribs);
     // save form submit
     $formSubmit->save();
     // Get Form Submit Id
     $formSubmitId = $formSubmit->id;
     // Save Form Fields
     foreach ($fields as $field) {
         if (!$field->compress) {
             $formSubmitField = new FormSubmitField();
             $formSubmitField->formSubmitId = $formSubmitId;
             $formSubmitField->name = $field->name;
             $fieldName = $field->name;
             $formSubmitField->value = $this->{$fieldName};
             $formSubmitField->save();
         }
     }
     return $formSubmit;
 }
Exemplo n.º 2
0
 public static function findById($id)
 {
     return FormSubmit::findById($id);
 }
Exemplo n.º 3
0
 /**
  * @return FormSubmit - the parent
  */
 public function getFormSubmit()
 {
     return $this->hasOne(FormSubmit::className(), ['id' => 'formSubmitId']);
 }