コード例 #1
0
 public function actionForm($id)
 {
     $cs = Yii::app()->getClientScript();
     $cs->setIsolationMode();
     $contactWebForm = static::getModelAndCatchNotFoundAndDisplayError('ContactWebForm', intval($id));
     $metadata = static::getMetadataByWebForm($contactWebForm);
     if ($contactWebForm->language !== null) {
         Yii::app()->language = $contactWebForm->language;
     }
     if (is_string($contactWebForm->submitButtonLabel) && !empty($contactWebForm->submitButtonLabel)) {
         $metadata['global']['toolbar']['elements'][0]['label'] = $contactWebForm->submitButtonLabel;
     }
     $customDisplayLabels = ContactWebFormsUtil::getCustomDisplayLabels($contactWebForm);
     $customRequiredFields = ContactWebFormsUtil::getCustomRequiredFields($contactWebForm);
     $contactWebFormModelForm = new ContactWebFormsModelForm(new Contact());
     $contactWebFormModelForm->state = $contactWebForm->defaultState;
     $contactWebFormModelForm->owner = $contactWebForm->defaultOwner;
     $contactWebFormModelForm->googleWebTrackingId = Yii::app()->getRequest()->getPost(ContactExternalEditAndDetailsView::GOOGLE_WEB_TRACKING_ID_FIELD);
     $contactWebFormModelForm->setCustomDisplayLabels($customDisplayLabels);
     $contactWebFormModelForm->setCustomRequiredFields($customRequiredFields);
     $contactWebFormModelForm->resolveRequiredValidatorsForModel($customRequiredFields);
     $postVariableName = get_class($contactWebFormModelForm);
     if (isset($_POST[$postVariableName])) {
         ContactWebFormsUtil::resolveHiddenAttributesForContactModel($postVariableName, $contactWebForm);
         $_POST[$postVariableName] = PostUtil::sanitizePostByDesignerTypeForSavingModel($contactWebFormModelForm->getModel(), $_POST[$postVariableName]);
         $contactWebFormModelForm->setAttributes($_POST[$postVariableName]);
         $this->attemptToValidate($contactWebForm, $contactWebFormModelForm);
         $this->attemptToSaveModelFromPost($contactWebFormModelForm, null, false);
         if (isset($contactWebFormModelForm->getModel()->id) && intval($contactWebFormModelForm->getModel()->id) > 0) {
             $this->resolveContactWebFormEntry($contactWebForm, $contactWebFormModelForm);
             $controllerUtil = static::getZurmoControllerUtil();
             $controllerUtil::setContactModelPermissionsByContactWebForm($contactWebFormModelForm->getModel(), $contactWebForm);
             $responseData = array();
             $responseData['redirectUrl'] = $contactWebForm->redirectUrl;
             $this->renderResponse(CJSON::encode($responseData));
         }
     } else {
         $containedView = new ContactExternalEditAndDetailsView('Edit', $this->getId(), $this->getModule()->getId(), $this->attemptToSaveModelFromPost($contactWebFormModelForm, null, false), $metadata);
         $view = new ContactWebFormsExternalPageView(ZurmoExternalViewUtil::makeExternalViewForCurrentUser($containedView));
         $cs->registerScript('catchGoogleWebTrackingId', "\n                                    \$(document).ready(function()\n                                    {\n                                        \$('html').addClass('zurmo-embedded-form-active');\n                                        if (typeof ga !== 'undefined')\n                                        {\n                                            ga(function(tracker)\n                                            {\n                                                var googleWebTrackingId = tracker.get('clientId');\n                                                \$('#" . ContactExternalEditAndDetailsView::GOOGLE_WEB_TRACKING_ID_FIELD . "').val(googleWebTrackingId);\n                                            });\n                                        }\n                                    });");
         $excludeStyles = $contactWebForm->excludeStyles;
         $rawXHtml = $view->render();
         $rawXHtml = ZurmoExternalViewUtil::resolveAndCombineScripts($rawXHtml);
         $combinedHtml = array();
         $combinedHtml['head'] = ZurmoExternalViewUtil::resolveHeadTag($rawXHtml, $excludeStyles);
         $combinedHtml['body'] = ZurmoExternalViewUtil::resolveHtmlAndScriptInBody($rawXHtml);
         if (isset($contactWebForm->enableCaptcha) && $contactWebForm->enableCaptcha == true) {
             $combinedHtml['enableCaptcha'] = true;
         } else {
             $combinedHtml['enableCaptcha'] = false;
         }
         $response = 'renderFormCallback(' . CJSON::encode($combinedHtml) . ');';
         $this->renderResponse($response);
     }
 }