/**
  * Get the formatted value
  *
  * The value can be formatted into HTML or plain text, arrays
  * are joined by $separator
  *
  * @param string $format plain or html
  * @param string $separator
  */
 public function getFormattedValue($format = 'plain', $separator = ', ')
 {
     $filteredValue = $this->getValue();
     $value = '';
     if ($format == 'html') {
         if (is_scalar($filteredValue)) {
             $value = nl2br(Quform::escape($filteredValue));
         } else {
             if (is_array($filteredValue)) {
                 foreach ($filteredValue as $val) {
                     if (is_scalar($val)) {
                         $value .= nl2br(Quform::escape($val)) . $separator;
                     }
                 }
             }
         }
     } else {
         if (is_scalar($filteredValue)) {
             $value = (string) $filteredValue;
         } else {
             if (is_array($filteredValue)) {
                 foreach ($filteredValue as $val) {
                     if (is_scalar($val)) {
                         $value .= (string) $val . $separator;
                     }
                 }
             }
         }
     }
     return $value;
 }
예제 #2
0
 /**
  * Get the value of the form element formatted in HTML
  *
  * @param string $separator The separator to join array types
  * @return string
  */
 public function getValueHtml($separator = '<br />')
 {
     $filteredValue = $this->getValue();
     $value = '';
     if (is_scalar($filteredValue)) {
         $value = nl2br(Quform::escape($filteredValue));
     } else {
         if (is_array($filteredValue)) {
             foreach ($filteredValue as $val) {
                 if (is_scalar($val)) {
                     $value .= nl2br(Quform::escape($val)) . $separator;
                 }
             }
         }
     }
     return $value;
 }
/** END FORM ELEMENT CONFIGURATION **/
function process(Quform $form, array &$config)
{
    // Process the form
    if ($form->isValid($_POST)) {
        // Custom code section #1 - see documentation for examples
        // End custom code section #1
        try {
            $attachments = array();
            $elements = $form->getElements();
            // Process uploaded files
            foreach ($elements as $element) {
                if ($element instanceof Quform_Element_File && array_key_exists($element->getName(), $_FILES) && is_array($_FILES[$element->getName()])) {
                    $file = $_FILES[$element->getName()];
                    if (is_array($file['error'])) {
                        // Process multiple upload field
                        foreach ($file['error'] as $key => $error) {
                            if ($error === UPLOAD_ERR_OK) {
                                $fileData = array('path' => $file['tmp_name'][$key], 'filename' => Quform_Element_File::filterFilename($file['name'][$key]), 'type' => $file['type'][$key], 'size' => $file['size'][$key]);
                                if ($config['saveUploads'] && $element->getSave()) {
                                    $result = Quform_Element_File::saveUpload($config['uploadPath'], $config['uploadUrl'], $fileData, $element);
                                    if (is_array($result)) {
                                        $fileData = $result;
                                    }
                                }
                                if ($element->getAttach()) {
                                    $attachments[] = $fileData;
                                }
                                $element->addFile($fileData);
                            }
                        }
                    } else {
                        // Process single upload field
                        if ($file['error'] === UPLOAD_ERR_OK) {
                            $fileData = array('path' => $file['tmp_name'], 'filename' => Quform_Element_File::filterFilename($file['name']), 'type' => $file['type'], 'size' => $file['size']);
                            if ($config['saveUploads'] && $element->getSave()) {
                                $result = Quform_Element_File::saveUpload($config['uploadPath'], $config['uploadUrl'], $fileData, $element);
                                if (is_array($result)) {
                                    $fileData = $result;
                                }
                            }
                            if ($element->getAttach()) {
                                $attachments[] = $fileData;
                            }
                            $element->addFile($fileData);
                        }
                    }
                }
                // element exists in $_FILES
            }
            // foreach element
            // Save to a MySQL database
            if ($config['database']) {
                // Connect to MySQL
                mysql_connect('localhost', 'username', 'password') or die(mysql_error());
                // Select the database
                mysql_select_db('database') or die(mysql_error());
                // Set the connection encoding
                if (strtolower(QUFORM_CHARSET) == 'utf-8') {
                    mysql_query("SET NAMES utf8") or die(mysql_error());
                }
                // Build the query
                $query = "INSERT INTO table SET ";
                $query .= "`name` = '" . mysql_real_escape_string($form->getValue('name')) . "',";
                $query .= "`email` = '" . mysql_real_escape_string($form->getValue('email')) . "',";
                $query .= "`message` = '" . mysql_real_escape_string($form->getValue('message')) . "';";
                // Careful! The last line ends in a semi-colon
                // Execute the query
                mysql_query($query) or die(mysql_error());
                // Close the connection
                mysql_close();
            }
            if ($config['email']) {
                // Get a new PHPMailer instance
                $mailer = Quform::newPHPMailer($config['smtp']);
                // Set the from information
                $from = $form->parseEmailRecipient($config['from']);
                if ($from['email']) {
                    $mailer->From = $from['email'];
                    $mailer->FromName = $from['name'];
                }
                // Set the Reply-To header of the email as the submitted email address from the form
                if (!empty($config['replyTo'])) {
                    $replyTo = $form->parseEmailRecipient($config['replyTo']);
                    if ($replyTo['email']) {
                        $mailer->AddReplyTo($replyTo['email'], $replyTo['name']);
                    }
                }
                // Set the subject
                $mailer->Subject = $form->replacePlaceholderValues($config['subject']);
                // Set the recipients
                foreach ((array) $config['recipients'] as $recipient) {
                    $mailer->AddAddress($recipient);
                }
                // Set the message body HTML
                ob_start();
                include QUFORM_ROOT . $config['emailBody'];
                $mailer->MsgHTML(ob_get_clean());
                $mailer->AltBody = 'To view this email please use HTML compatible email software.';
                // Add any attachments
                foreach ($attachments as $attachment) {
                    $mailer->AddAttachment($attachment['path'], $attachment['filename'], 'base64', $attachment['type']);
                }
                // Send the notification message
                $mailer->Send();
            }
            // Autoreply email
            if ($config['autoreply']) {
                $autoreplyRecipient = $form->parseEmailRecipient($config['autoreplyRecipient']);
                if ($autoreplyRecipient['email']) {
                    // Create the autoreply message
                    $mailer = Quform::newPHPMailer($config['smtp']);
                    // Set the from address
                    $autoreplyFrom = $form->parseEmailRecipient($config['autoreplyFrom']);
                    if ($autoreplyFrom['email']) {
                        $mailer->From = $autoreplyFrom['email'];
                        $mailer->FromName = $autoreplyFrom['name'];
                    }
                    // Set the recipient
                    $mailer->AddAddress($autoreplyRecipient['email'], $autoreplyRecipient['name']);
                    // Set the subject
                    $mailer->Subject = $form->replacePlaceholderValues($config['autoreplySubject']);
                    // Set the message body HTML
                    ob_start();
                    include QUFORM_ROOT . $config['autoreplyBody'];
                    $mailer->MsgHTML(ob_get_clean());
                    $mailer->AltBody = 'To view this email please use HTML compatible email software.';
                    // Send the autoreply
                    $mailer->Send();
                }
            }
            // Custom code section #2 - see documentation for examples
            // End custom code section #2
        } catch (Exception $e) {
            if (QUFORM_DEBUG) {
                throw $e;
            }
        }
    } else {
        // Form data failed validation
        return false;
    }
    // Form processed successfully
    return true;
}
                            </tr>
                        <?php 
    }
    ?>
                    <?php 
}
?>
                    <?php 
if (isset($config['extra']) && is_array($config['extra']) && count($config['extra'])) {
    ?>
                        <?php 
    foreach ($config['extra'] as $key => $value) {
        ?>
                            <tr>
                                <td valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 17px; font-weight: bold; color: #282828; width: 25%;"><?php 
        echo Quform::escape($key);
        ?>
</td>
                                <td valign="top" style="font-family: Helvetica, Arial, sans-serif; color: #282828; line-height: 130%; width: 75%;"><?php 
        echo $value;
        ?>
</td>
                            </tr>
                        <?php 
    }
    ?>
                    <?php 
}
?>
                </table>
                </td>
예제 #5
0
        if (count($result['elementErrors'])) {
            ?>
                            <div class="quform-errors-outer quform-cf">
                                <?php 
            foreach ($result['elementErrors'] as $name => $info) {
                ?>
                                    <?php 
                if (count($info['errors'])) {
                    ?>
                                        <div class="quform-error-wrap quform-cf">
                                            <div class="quform-error-label"><?php 
                    echo Quform::escape($info['label']);
                    ?>
</div>
                                            <div class="quform-errors quform-cf"><div class="quform-error"><?php 
                    echo Quform::escape($info['errors'][0]);
                    ?>
</div></div>
                                        </div>
                                    <?php 
                }
                ?>
                                <?php 
            }
            ?>
                            </div>
                        <?php 
        }
        ?>
                    <?php 
    } elseif ($result['type'] == 'success') {
예제 #6
0
if ($_SERVER['REQUEST_METHOD'] != 'POST' || !defined('QUFORM_ROOT')) {
    exit;
}
if (version_compare(PHP_VERSION, '5.0.0', '<')) {
    die('Quform requires PHP 5 or later, the server is running version ' . PHP_VERSION);
}
// Enable error reporting if debug mode is on
if (defined('QUFORM_DEBUG') && QUFORM_DEBUG) {
    error_reporting(E_ALL);
    @ini_set('display_errors', 'On');
} else {
    error_reporting(0);
    @ini_set('display_errors', 'Off');
}
// Define constants
defined('QUFORM_CHARSET') || define('QUFORM_CHARSET', 'UTF-8');
defined('QUFORM_UPLOAD_ERR_TYPE') || define('QUFORM_UPLOAD_ERR_TYPE', 128);
defined('QUFORM_UPLOAD_ERR_FILE_SIZE') || define('QUFORM_UPLOAD_ERR_FILE_SIZE', 129);
defined('QUFORM_UPLOAD_ERR_NOT_UPLOADED') || define('QUFORM_UPLOAD_ERR_NOT_UPLOADED', 130);
defined('QUFORM_HTMLSPECIALCHARS_DOUBLE_ENCODE') || define('QUFORM_HTMLSPECIALCHARS_DOUBLE_ENCODE', version_compare(PHP_VERSION, '5.2.3', '>='));
// Include required libraries
require_once QUFORM_ROOT . '/lib/Quform.php';
require_once QUFORM_ROOT . '/lib/class.phpmailer.php';
require_once QUFORM_ROOT . '/lib/recaptchalib.php';
Quform::registerAutoload();
// Instantiate the form
$form = new Quform();
// Strip slashes from the posted data if magic quotes is on
if (get_magic_quotes_gpc()) {
    $_POST = Quform::stripslashes($_POST);
}
예제 #7
0
<?php

if (!defined('QUFORM_ROOT')) {
    exit;
}
?>
<html>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td valign="top" style="padding: 25px;"><table width="600" cellpadding="0" cellspacing="0" border="0" style="font: 14px Helvetica, Arial, sans-serif;">
            <tr>
                <td valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 25px; font-weight: bold; color: #282828; padding-bottom: 10px;"><?php 
echo Quform::escape($mailer->Subject);
?>
</td>
            </tr>
            <tr>
                <td valign="top">Just to let you know we received your message and we will get back to you as soon as possible.</td>
            </tr>
        </table></td>
    </tr>
</table>
</body>
</html>