/** * 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; }
/** * {@inheritDoc} */ public function getFields() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getFields', array()); return parent::getFields(); }
/** * 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; } } } }
/** * @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); } } } }