/** * Note if this submission is from a focus submit. * * @param SubmissionEvent $event */ public function onFormSubmit(SubmissionEvent $event) { // Check the request for a focus field $id = $this->request->request->get('mauticform[focusId]', false, true); if (!empty($id)) { $focus = $this->model->getEntity($id); if ($focus && $focus->isPublished()) { // Make sure the form is still applicable $form = $event->getSubmission()->getForm(); if ((int) $form->getId() === (int) $focus->getForm()) { $this->model->addStat($focus, Stat::TYPE_FORM, $event->getSubmission()); } } } }
public function onFormSubmit(SubmissionEvent $event) { $types = array(FormEvents::FORM_ON_SUBMIT); $groups = array('submissionDetails', 'ipAddress', 'leadList', 'pageList', 'formList'); $form = $event->getSubmission(); $payload = array('submission' => $form); $webhooks = $this->getEventWebooksByType($types); $this->webhookModel->QueueWebhooks($webhooks, $payload, $groups, true); }
/** * @param Events\SubmissionEvent $event */ public function onFormSubmitActionRepost(Events\SubmissionEvent $event) { if (!$event->checkContext('form.repost')) { return; } $post = $event->getPost(); $results = $event->getResults(); $config = $event->getActionConfig(); $fields = $event->getFields(); $lead = $event->getSubmission()->getLead(); $matchedFields = []; $payload = ['mautic_contact' => $lead->getProfileFields(), 'mautic_form' => ['id' => $post['formId'], 'name' => $post['formName'], 'url' => $post['return']]]; $fieldTypes = []; foreach ($fields as $field) { $fieldTypes[$field['alias']] = $field['type']; if (!isset($post[$field['alias']]) || 'button' == $field['type']) { continue; } $key = !empty($config[$field['alias']]) ? $config[$field['alias']] : $field['alias']; // Use the cleaned value by default - but if set to not save result, get from post $value = isset($results[$field['alias']]) ? $results[$field['alias']] : $post[$field['alias']]; $matchedFields[$key] = $field['alias']; $payload[$key] = $value; } $headers = ['X-Forwarded-For' => $event->getSubmission()->getIpAddress()->getIpAddress()]; if (!empty($config['authorization_header'])) { if (strpos($config['authorization_header'], ':') !== false) { list($key, $value) = explode(':', $config['authorization_header']); } else { $key = 'Authorization'; $value = $config['authorization_header']; } $headers[trim($key)] = trim($value); } try { $client = new Client(['timeout' => 15]); $response = $client->post($config['post_url'], ['form_params' => $payload, 'headers' => $headers]); if ($redirect = $this->parseResponse($response, $matchedFields)) { $event->setPostSubmitCallbackResponse('form.repost', new RedirectResponse($redirect)); } } catch (ServerException $exception) { $this->parseResponse($exception->getResponse(), $matchedFields); } catch (\Exception $exception) { if ($exception instanceof ValidationException) { if ($violations = $exception->getViolations()) { throw $exception; } } $email = $config['failure_email']; // Failed so send email if applicable if (!empty($email)) { // Remove Mautic values and password fields foreach ($post as $key => $value) { if (in_array($key, ['messenger', 'submit', 'formId', 'formid', 'formName', 'return'])) { unset($post[$key]); } if (isset($fieldTypes[$key]) && in_array($fieldTypes[$key], ['password'])) { $post[$key] = '*********'; } } $post['mautic_contact'] = array_filter($payload['mautic_contact']); $post['mautic_form'] = $payload['mautic_form']; $results = $this->postToHtml($post); $submission = $event->getSubmission(); $emails = $emails = $this->getEmailsFromString($email); $this->mailer->setTo($emails); $this->mailer->setSubject($this->translator->trans('mautic.form.action.repost.failed_subject', ['%form%' => $submission->getForm()->getName()])); $this->mailer->setBody($this->translator->trans('mautic.form.action.repost.failed_message', ['%link%' => $this->router->generate('mautic_form_results', ['objectId' => $submission->getForm()->getId(), 'result' => $submission->getId()], UrlGeneratorInterface::ABSOLUTE_URL), '%message%' => $exception->getMessage(), '%results%' => $results])); $this->mailer->parsePlainText(); $this->mailer->send(); } } }
/** * @deprecated - added for BC; to be removed in 3.0 * * @param Action[] $actions * @param SubmissionEvent $event * @param $validationErrors * @param $lastAlias Because prior to now the last alias was used regardless */ protected function validateActionCallbacks(SubmissionEvent $event, &$validationErrors, $lastAlias) { $args = ['post' => $event->getPost(), 'server' => $event->getServer(), 'factory' => $this->factory, 'submission' => $event->getSubmission(), 'fields' => $event->getFields(), 'form' => $event->getSubmission()->getForm(), 'tokens' => $event->getTokens()]; $actions = $event->getSubmission()->getForm()->getActions(); $availableActions = $this->formModel->getCustomComponents()['actions']; foreach ($actions as $action) { $key = $action->getType(); if (!isset($availableActions[$key])) { continue; } $settings = $availableActions[$key]; $args['action'] = $action; $args['config'] = $action->getProperties(); if (array_key_exists('validator', $settings)) { $callback = $settings['validator']; if (is_callable($callback)) { if (is_array($callback)) { $reflection = new \ReflectionMethod($callback[0], $callback[1]); } elseif (strpos($callback, '::') !== false) { $parts = explode('::', $callback); $reflection = new \ReflectionMethod($parts[0], $parts[1]); } else { $reflection = new \ReflectionMethod(null, $callback); } $pass = []; foreach ($reflection->getParameters() as $param) { if (isset($args[$param->getName()])) { $pass[] = $args[$param->getName()]; } else { $pass[] = null; } } list($validated, $validatedMessage) = $reflection->invokeArgs($this, $pass); if (!$validated) { $validationErrors[$lastAlias] = $validatedMessage; } } } } unset($args, $actions, $availableActions); }
/** * Trigger point actions for form submit * * @param SubmissionEvent $event */ public function onFormSubmit(SubmissionEvent $event) { $this->factory->getModel('point')->triggerAction('form.submit', $event->getSubmission()); }
/** * Trigger campaign event for when a form is submitted * * @param FormEvent $event */ public function onFormSubmit(SubmissionEvent $event) { $form = $event->getSubmission()->getForm(); $this->factory->getModel('campaign')->triggerEvent('form.submit', $form, 'form.submit' . $form->getId()); }
/** * Trigger point actions for form submit. * * @param SubmissionEvent $event */ public function onFormSubmit(SubmissionEvent $event) { $this->pointModel->triggerAction('form.submit', $event->getSubmission()); }