Example #1
0
 /**
  * Run any postHooks that were specified.
  *
  * @return boolean True if all hooks executed successfully.
  */
 public function runPostHooks()
 {
     $success = true;
     /* load posthooks */
     $this->formit->loadHooks('post', $this->config);
     $this->formit->postHooks->loadMultiple($this->config['hooks'], $this->dictionary->toArray());
     /* process form */
     if ($this->formit->preHooks->hasErrors() && $this->modx->getOption('preventPostHooksIfPreHooksErrors', $this->config, true)) {
         /* prevent scripts from running with prehook errors */
         $success = false;
         $this->formit->preHooks->processErrors();
     } elseif ($this->formit->postHooks->hasErrors()) {
         $success = false;
         $this->formit->postHooks->processErrors();
     } else {
         /* assign new values from postHooks */
         $this->dictionary->fromArray($this->formit->postHooks->fields);
     }
     return $success;
 }
 /**
  * Erase the stored fields
  * 
  * @return boolean
  */
 public function erase()
 {
     $cacheKey = $this->formit->getStoreKey();
     return $this->modx->cacheManager->delete($cacheKey);
 }
 * FormIt is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option) any
 * later version.
 *
 * FormIt is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * FormIt; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA 02111-1307 USA
 *
 * @package formit
 */
/**
 * Automatically generates and outputs a country list for usage in forms
 *
 * @var modX $modx
 * @var array $scriptProperties
 * @package formit
 */
require_once $modx->getOption('formit.core_path', null, $modx->getOption('core_path') . 'components/formit/') . 'model/formit/formit.class.php';
$fi = new FormIt($modx, $scriptProperties);
/** @var fiCountryOptions $co */
$co = $fi->loadModule('fiCountryOptions', 'countryOptions', $scriptProperties);
$co->initialize();
$co->getData();
$co->loadPrioritized();
$co->iterate();
return $co->output();
 *
 * Copyright 2009-2012 by Shaun McCormick <*****@*****.**>
 *
 * FormIt is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option) any
 * later version.
 *
 * FormIt is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * FormIt; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA 02111-1307 USA
 *
 * @package formit
 */
/**
 * Automatically generates and outputs a U.S. state list for usage in forms
 * 
 * @package formit
 */
require_once $modx->getOption('formit.core_path', null, $modx->getOption('core_path') . 'components/formit/') . 'model/formit/formit.class.php';
$fi = new FormIt($modx, $scriptProperties);
/** @var fiCountryOptions $co */
$co = $fi->loadModule('fiStateOptions', 'stateOptions', $scriptProperties);
$co->initialize();
$co->getData();
$co->iterate();
return $co->output();
Example #5
0
 /**
  * Go ahead and send the form through the request handler. Used as a shortcut method.
  * @return void
  */
 public function processForm()
 {
     $request = $this->formit->loadRequest();
     $fields = $request->prepare();
     $request->handle($fields);
 }
 * FormIt; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA 02111-1307 USA
 *
 * @package formit
 */
/**
 * Retrieves a prior form submission that was stored with the &store property
 * in a FormIt call.
 *
 * @var modX $modx
 * @var array $scriptProperties
 * 
 * @package formit
 */
require_once $modx->getOption('formit.core_path', null, $modx->getOption('core_path') . 'components/formit/') . 'model/formit/formit.class.php';
$fi = new FormIt($modx, $scriptProperties);
/* setup properties */
$placeholderPrefix = $modx->getOption('placeholderPrefix', $scriptProperties, 'fi.');
$eraseOnLoad = $modx->getOption('eraseOnLoad', $scriptProperties, false);
$redirectToOnNotFound = $modx->getOption('redirectToOnNotFound', $scriptProperties, false);
/* fetch data from cache and set to placeholders */
$fi->loadRequest();
$fi->request->loadDictionary();
$data = $fi->request->dictionary->retrieve();
if (!empty($data)) {
    /* set data to placeholders */
    foreach ($data as $k => $v) {
        /*checkboxes & other multi-values are stored as arrays, must be imploded*/
        if (is_array($v)) {
            $data[$k] = implode(',', $v);
        }
 /**
  * Send an email of the form.
  *
  * Properties:
  * - emailTpl - The chunk name of the chunk that will be the email template.
  * This will send the values of the form as placeholders.
  * - emailTo - A comma separated list of email addresses to send to
  * - emailToName - A comma separated list of names to pair with addresses.
  * - emailFrom - The From: email address. Defaults to either the email
  * field or the emailsender setting.
  * - emailFromName - The name of the From: user.
  * - emailSubject - The subject of the email.
  * - emailHtml - Boolean, if true, email will be in HTML mode.
  *
  * @access public
  * @param array $fields An array of cleaned POST fields
  * @return boolean True if email was successfully sent.
  */
 public function email(array $fields = array())
 {
     $tpl = $this->modx->getOption('emailTpl', $this->formit->config, '');
     $emailHtml = (bool) $this->modx->getOption('emailHtml', $this->formit->config, true);
     $emailConvertNewlines = (bool) $this->modx->getOption('emailConvertNewlines', $this->formit->config, false);
     /* get from name */
     $emailFrom = $this->modx->getOption('emailFrom', $this->formit->config, '');
     if (empty($emailFrom)) {
         $emailFrom = !empty($fields['email']) ? $fields['email'] : $this->modx->getOption('emailsender');
     }
     $emailFrom = $this->_process($emailFrom, $fields);
     $emailFromName = $this->modx->getOption('emailFromName', $this->formit->config, $emailFrom);
     $emailFromName = $this->_process($emailFromName, $fields);
     /* get subject */
     $useEmailFieldForSubject = $this->modx->getOption('emailUseFieldForSubject', $this->formit->config, true);
     if (!empty($fields['subject']) && $useEmailFieldForSubject) {
         $subject = $fields['subject'];
     } else {
         $subject = $this->modx->getOption('emailSubject', $this->formit->config, '');
     }
     $subject = $this->_process($subject, $fields);
     /* check email to */
     $emailTo = $this->modx->getOption('emailTo', $this->formit->config, '');
     $emailToName = $this->modx->getOption('emailToName', $this->formit->config, $emailTo);
     if (empty($emailTo)) {
         $this->errors['emailTo'] = $this->modx->lexicon('formit.email_no_recipient');
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[FormIt] ' . $this->modx->lexicon('formit.email_no_recipient'));
         return false;
     }
     /* compile message */
     $origFields = $fields;
     if (empty($tpl)) {
         $tpl = 'email';
         $f = '';
         $multiSeparator = $this->modx->getOption('emailMultiSeparator', $this->formit->config, "\n");
         $multiWrapper = $this->modx->getOption('emailMultiWrapper', $this->formit->config, "[[+value]]");
         foreach ($fields as $k => $v) {
             if ($k == 'nospam') {
                 continue;
             }
             if (is_array($v) && !empty($v['name']) && isset($v['error']) && $v['error'] == UPLOAD_ERR_OK) {
                 $v = $v['name'];
                 $f[$k] = '<strong>' . $k . '</strong>: ' . $v . '<br />';
             } else {
                 if (is_array($v)) {
                     $vOpts = array();
                     foreach ($v as $vKey => $vValue) {
                         if (is_string($vKey) && !empty($vKey)) {
                             $vKey = $k . '.' . $vKey;
                             $f[$vKey] = '<strong>' . $vKey . '</strong>: ' . $vValue . '<br />';
                         } else {
                             $vOpts[] = str_replace('[[+value]]', $vValue, $multiWrapper);
                         }
                     }
                     $newValue = implode($multiSeparator, $vOpts);
                     if (!empty($vOpts)) {
                         $f[$k] = '<strong>' . $k . '</strong>:' . $newValue;
                     }
                 } else {
                     $f[$k] = '<strong>' . $k . '</strong>: ' . $v . '<br />';
                 }
             }
         }
         $fields['fields'] = implode("\n", $f);
     } else {
         /* handle file/checkboxes in email tpl */
         $multiSeparator = $this->modx->getOption('emailMultiSeparator', $this->formit->config, "\n");
         if (empty($multiSeparator)) {
             $multiSeparator = "\n";
         }
         if ($multiSeparator == '\\n') {
             $multiSeparator = "\n";
         }
         /* allow for inputted newlines */
         $multiWrapper = $this->modx->getOption('emailMultiWrapper', $this->formit->config, "[[+value]]");
         if (empty($multiWrapper)) {
             $multiWrapper = '[[+value]]';
         }
         foreach ($fields as $k => &$v) {
             if (is_array($v) && !empty($v['name']) && isset($v['error']) && $v['error'] == UPLOAD_ERR_OK) {
                 $v = $v['name'];
             } else {
                 if (is_array($v)) {
                     $vOpts = array();
                     foreach ($v as $vKey => $vValue) {
                         if (is_string($vKey) && !empty($vKey)) {
                             $vKey = $k . '.' . $vKey;
                             $fields[$vKey] = $vValue;
                             unset($fields[$k]);
                         } else {
                             $vOpts[] = str_replace('[[+value]]', $vValue, $multiWrapper);
                         }
                     }
                     $v = implode($multiSeparator, $vOpts);
                 }
             }
         }
     }
     $message = $this->formit->getChunk($tpl, $fields);
     $message = $this->_process($message, $this->config);
     /* load mail service */
     $this->modx->getService('mail', 'mail.modPHPMailer');
     /* set HTML */
     $this->modx->mail->setHTML($emailHtml);
     /* set email main properties */
     $this->modx->mail->set(modMail::MAIL_BODY, $emailHtml && $emailConvertNewlines ? nl2br($message) : $message);
     $this->modx->mail->set(modMail::MAIL_FROM, $emailFrom);
     $this->modx->mail->set(modMail::MAIL_FROM_NAME, $emailFromName);
     $this->modx->mail->set(modMail::MAIL_SENDER, $emailFrom);
     $this->modx->mail->set(modMail::MAIL_SUBJECT, $subject);
     /* handle file fields */
     foreach ($origFields as $k => $v) {
         $attachmentIndex = 0;
         if (is_array($v) && !empty($v['tmp_name']) && isset($v['error']) && $v['error'] == UPLOAD_ERR_OK) {
             if (empty($v['name'])) {
                 $v['name'] = 'attachment' . $attachmentIndex;
             }
             $this->modx->mail->mailer->AddAttachment($v['tmp_name'], $v['name'], 'base64', !empty($v['type']) ? $v['type'] : 'application/octet-stream');
             $attachmentIndex++;
         }
     }
     /* add to: with support for multiple addresses */
     $emailTo = explode(',', $emailTo);
     $emailToName = explode(',', $emailToName);
     $numAddresses = count($emailTo);
     for ($i = 0; $i < $numAddresses; $i++) {
         $etn = !empty($emailToName[$i]) ? $emailToName[$i] : '';
         if (!empty($etn)) {
             $etn = $this->_process($etn, $fields);
         }
         $emailTo[$i] = $this->_process($emailTo[$i], $fields);
         if (!empty($emailTo[$i])) {
             $this->modx->mail->address('to', $emailTo[$i], $etn);
         }
     }
     /* reply to */
     $emailReplyTo = $this->modx->getOption('emailReplyTo', $this->formit->config, $emailFrom);
     $emailReplyTo = $this->_process($emailReplyTo, $fields);
     $emailReplyToName = $this->modx->getOption('emailReplyToName', $this->formit->config, $emailFromName);
     $emailReplyToName = $this->_process($emailReplyToName, $fields);
     if (!empty($emailReplyTo)) {
         $this->modx->mail->address('reply-to', $emailReplyTo, $emailReplyToName);
     }
     /* cc */
     $emailCC = $this->modx->getOption('emailCC', $this->formit->config, '');
     if (!empty($emailCC)) {
         $emailCCName = $this->modx->getOption('emailCCName', $this->formit->config, '');
         $emailCC = explode(',', $emailCC);
         $emailCCName = explode(',', $emailCCName);
         $numAddresses = count($emailCC);
         for ($i = 0; $i < $numAddresses; $i++) {
             $etn = !empty($emailCCName[$i]) ? $emailCCName[$i] : '';
             if (!empty($etn)) {
                 $etn = $this->_process($etn, $fields);
             }
             $emailCC[$i] = $this->_process($emailCC[$i], $fields);
             if (!empty($emailCC[$i])) {
                 $this->modx->mail->address('cc', $emailCC[$i], $etn);
             }
         }
     }
     /* bcc */
     $emailBCC = $this->modx->getOption('emailBCC', $this->formit->config, '');
     if (!empty($emailBCC)) {
         $emailBCCName = $this->modx->getOption('emailBCCName', $this->formit->config, '');
         $emailBCC = explode(',', $emailBCC);
         $emailBCCName = explode(',', $emailBCCName);
         $numAddresses = count($emailBCC);
         for ($i = 0; $i < $numAddresses; $i++) {
             $etn = !empty($emailBCCName[$i]) ? $emailBCCName[$i] : '';
             if (!empty($etn)) {
                 $etn = $this->_process($etn, $fields);
             }
             $emailBCC[$i] = $this->_process($emailBCC[$i], $fields);
             if (!empty($emailBCC[$i])) {
                 $this->modx->mail->address('bcc', $emailBCC[$i], $etn);
             }
         }
     }
     /* send email */
     if (!$this->formit->inTestMode) {
         $sent = $this->modx->mail->send();
     } else {
         $sent = true;
     }
     $this->modx->mail->reset(array(modMail::MAIL_CHARSET => $this->modx->getOption('mail_charset', null, 'UTF-8'), modMail::MAIL_ENCODING => $this->modx->getOption('mail_encoding', null, '8bit')));
     if (!$sent) {
         $this->errors[] = $this->modx->lexicon('formit.email_not_sent') . ' ' . print_r($this->modx->mail->mailer->ErrorInfo, true);
         $this->modx->log(modX::LOG_LEVEL_ERROR, '[FormIt] ' . $this->modx->lexicon('formit.email_not_sent') . ' ' . print_r($this->modx->mail->mailer->ErrorInfo, true));
     }
     return $sent;
 }
Example #8
0
 *
 * Copyright 2009-2012 by Shaun McCormick <*****@*****.**>
 *
 * FormIt is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option) any
 * later version.
 *
 * FormIt is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * FormIt; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 * Suite 330, Boston, MA 02111-1307 USA
 *
 * @package formit
 */
/**
 * FormIt
 *
 * A dynamic form processing Snippet for MODx Revolution.
 *
 * @package formit
 */
require_once $modx->getOption('formit.core_path', null, $modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/formit/') . 'model/formit/formit.class.php';
$fi = new FormIt($modx, $scriptProperties);
$fi->initialize($modx->context->get('key'));
$fi->loadRequest();
$fields = $fi->request->prepare();
return $fi->request->handle($fields);