/** * Determine if this campaign applies * * @param $eventDetails * @param $event * * @return bool */ public static function validateFormSubmit(Form $eventDetails = null, $event) { if ($eventDetails == null) { return true; } $limitToForms = $event['properties']['forms']; //check against selected forms if (!empty($limitToForms) && !in_array($eventDetails->getId(), $limitToForms)) { return false; } return true; }
/** * @param Form $form * @param Asset $asset * @param MauticFactory $factory * @param $message * @param $messageMode * * @return RedirectResponse|Response */ public static function downloadFile(Form $form, Asset $asset, MauticFactory $factory, $message, $messengerMode) { /** @var \Mautic\AssetBundle\Model\AssetModel $model */ $model = $factory->getModel('asset'); $url = $model->generateUrl($asset, true, array('form', $form->getId())); if ($messengerMode) { return array('download' => $url); } $msg = $message . $factory->getTranslator()->trans('mautic.asset.asset.submitaction.downloadfile.msg', array('%url%' => $url)); $content = $factory->getTemplating()->renderResponse('MauticCoreBundle::message.html.php', array('message' => $msg, 'type' => 'notice', 'template' => $factory->getParameter('theme')))->getContent(); return new Response($content); }
/** * @param Form $form * @param Asset $asset * @param MauticFactory $factory * @param $message * @param $messageMode * * @return RedirectResponse|Response */ public static function downloadFile(Form $form, Asset $asset, MauticFactory $factory, $message, $messengerMode) { /** @var \Mautic\AssetBundle\Model\AssetModel $model */ $model = $factory->getModel('asset'); $url = $model->generateUrl($asset, true, ['form', $form->getId()]); if ($messengerMode) { return ['download' => $url]; } $msg = $message . $factory->getTranslator()->trans('mautic.asset.asset.submitaction.downloadfile.msg', ['%url%' => $url]); $analytics = $factory->getHelper('template.analytics')->getCode(); if (!empty($analytics)) { $factory->getHelper('template.assets')->addCustomDeclaration($analytics); } $logicalName = $factory->getHelper('theme')->checkForTwigTemplate(':' . $factory->getParameter('theme') . ':message.html.php'); $content = $factory->getTemplating()->renderResponse($logicalName, ['message' => $msg, 'type' => 'notice', 'template' => $factory->getParameter('theme')])->getContent(); return new Response($content); }
/** * Generate an array of columns from fields * * @param Form $form * * @return array */ public function generateFieldColumns(Form $form) { $fields = $form->getFields(); $columns = array(array('name' => 'submission_id', 'type' => 'integer'), array('name' => 'form_id', 'type' => 'integer')); $ignoreTypes = array('button', 'freetext'); foreach ($fields as $f) { if (!in_array($f->getType(), $ignoreTypes) && $f->getSaveResult() !== false) { $columns[] = array('name' => $f->getAlias(), 'type' => 'text', 'options' => array('notnull' => false)); } } return $columns; }
/** * Writes in form values from get parameters * * @param $form * @param $formHtml */ public function populateValuesWithGetParameters(Form $form, &$formHtml) { $request = $this->factory->getRequest(); $formName = $form->generateFormName(); $fields = $form->getFields(); /** @var \Mautic\FormBundle\Entity\Field $f */ foreach ($fields as $f) { $alias = $f->getAlias(); if ($request->query->has($alias)) { $value = $request->query->get($alias); switch ($f->getType()) { case 'text': case 'email': case 'hidden': if (preg_match('/<input(.*?)id="mauticform_input_' . $formName . '_' . $alias . '"(.*?)value="(.*?)"(.*?)\\/>/i', $formHtml, $match)) { $replace = '<input' . $match[1] . 'id="mauticform_input_' . $formName . '_' . $alias . '"' . $match[2] . 'value="' . urldecode($value) . '"' . $match[4] . '/>'; $formHtml = str_replace($match[0], $replace, $formHtml); } break; case 'textarea': if (preg_match('/<textarea(.*?)id="mauticform_input_' . $formName . '_' . $alias . '"(.*?)>(.*?)<\\/textarea>/i', $formHtml, $match)) { $replace = '<textarea' . $match[1] . 'id="mauticform_input_' . $formName . '_' . $alias . '"' . $match[2] . '>' . urldecode($value) . '</textarea>'; $formHtml = str_replace($match[0], $replace, $formHtml); } break; case 'checkboxgrp': if (!is_array($value)) { $value = array($value); } foreach ($value as $val) { $val = urldecode($val); if (preg_match('/<input(.*?)id="mauticform_checkboxgrp_checkbox(.*?)"(.*?)value="' . $val . '"(.*?)\\/>/i', $formHtml, $match)) { $replace = '<input' . $match[1] . 'id="mauticform_checkboxgrp_checkbox' . $match[2] . '"' . $match[3] . 'value="' . $val . '"' . $match[4] . ' checked />'; $formHtml = str_replace($match[0], $replace, $formHtml); } } break; case 'radiogrp': $value = urldecode($value); if (preg_match('/<input(.*?)id="mauticform_radiogrp_radio(.*?)"(.*?)value="' . $value . '"(.*?)\\/>/i', $formHtml, $match)) { $replace = '<input' . $match[1] . 'id="mauticform_radiogrp_radio' . $match[2] . '"' . $match[3] . 'value="' . $value . '"' . $match[4] . ' checked />'; $formHtml = str_replace($match[0], $replace, $formHtml); } break; } } } }
/** * {@inheritDoc} */ public function __toString() { $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array()); return parent::__toString(); }
/** * Decide if the field should be displayed based on thr progressive profiling conditions * * @param array|null $submissions * @param Lead $lead * @param Form $form * * @return boolean */ public function showForContact($submissions = null, Lead $lead = null, Form $form = null) { // Always show in the kiosk mode if ($form !== null && $form->getInKioskMode() === true) { return true; } // Hide the field if there is the submission count limit and hide it untill the limit is overcame if ($this->showAfterXSubmissions > 0 && $this->showAfterXSubmissions > count($submissions)) { return false; } if ($this->showWhenValueExists === false) { // Hide the field if there is the value condition and if we already know the value for this field if ($submissions) { foreach ($submissions as $submission) { if (!empty($submission[$this->alias])) { return false; } } } // Hide the field if the value is already known from the lead profile if ($lead !== null && $this->leadField && $lead->getFieldValue($this->leadField) !== null) { return false; } } return true; }
/** * Remove form. * * @param Form $form */ public function removeForm(Form $form) { $this->changes['forms']['removed'][$form->getId()] = $form->getName(); $this->forms->removeElement($form); }
/** * @param Form $form * @param $formHtml */ public function populateValuesWithLead(Form $form, &$formHtml) { $formName = $form->generateFormName(); $lead = $this->leadModel->getCurrentLead(); $fields = $form->getFields(); /** @var \Mautic\FormBundle\Entity\Field $f */ foreach ($fields as $f) { $leadField = $f->getLeadField(); $isAutoFill = $f->getIsAutoFill(); if (isset($leadField) && $isAutoFill) { $value = $lead->getFieldValue($leadField); if (!empty($value)) { $this->fieldHelper->populateField($f, $value, $formName, $formHtml); } } } }
/** * Fetch the form results * * @param Form $form * @param array $options * * @return array * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ public function getFormResults(Form $form, array $options = array()) { $query = $this->_em->getConnection()->createQueryBuilder(); $query->from(MAUTIC_TABLE_PREFIX . 'form_submissions', 'fs')->select('fr.*')->leftJoin('fs', $this->getResultsTableName($form->getId(), $form->getAlias()), 'fr', 'fr.submission_id = fs.id')->where('fs.form_id = :formId')->setParameter('formId', $form->getId()); if (!empty($options['leadId'])) { $query->andWhere('fs.lead_id = ' . (int) $options['leadId']); } if (!empty($options['formId'])) { $query->andWhere($query->expr()->eq('fs.form_id', ':id'))->setParameter('id', $options['formId']); } if (!empty($options['limit'])) { $query->setMaxResults((int) $options['limit']); } return $query->execute()->fetchAll(); }
/** * Get the document write javascript for the form * * @param Form $form * @return string */ public function getAutomaticJavascript(Form $form) { $html = $form->getCachedHtml(); //replace line breaks with literal symbol and escape quotations $search = array("\n", '"'); $replace = array('\\n', '\\"'); $html = str_replace($search, $replace, $html); return "document.write(\"" . $html . "\");"; }