<?php /** * Mod Visforms Form * * @author Aicha Vack * @package Joomla.Site * @subpackage mod_visforms * @link http://www.vi-solutions.de * @license GNU General Public License version 2 or later; see license.txt * @copyright 2012 vi-solutions * @since Joomla 1.6 */ // no direct access defined('_JEXEC') or die('Restricted access'); JHTMLVisforms::includeScriptsOnlyOnce(); if ($visforms->published != '1') { return; } //retrieve helper variables from params $nbFields = $params->get('nbFields'); $required = $params->get('required'); $upload = $params->get('upload'); $textareaRequired = $params->get('textareaRequired'); $hasHTMLEditor = $params->get('hasHTMLEditor'); //helper, used to set focus on first visible field $firstControl = true; ?> <form action="<?php echo JRoute::_($formLink);
* Visforms bootstrap default view for Visforms * * @author Aicha Vack * @package Joomla.Site * @subpackage com_visforms * @link http://www.vi-solutions.de * @license GNU General Public License version 2 or later; see license.txt * @copyright 2012 vi-solutions * @since Joomla 1.6 */ // no direct access defined('_JEXEC') or die('Restricted access'); if ($this->visforms->published != '1') { return; } JHTMLVisforms::includeScriptsOnlyOnce(array('visforms' => false, 'bootstrapform' => $this->visforms->usebootstrapcss)); ?> <form action="<?php echo JRoute::_($this->formLink); ?> " method="post" name="visform" id="visform<?php echo $this->visforms->id; ?> " class="visform <?php echo $this->visforms->formCSSclass; echo $this->visforms->formlayout == "bthorizontal" ? " form-horizontal " : ""; ?> "<?php if ($this->upload == true) { ?>
/** * save a record (and redirect to main page) * and send emails * @return void */ function send() { $model = $this->getModel('visforms'); $visform = $model->getForm(); $spambotcheck = $visform->spambotcheck; $app = JFactory::getApplication(); $return = $app->input->post->get('return'); $url = isset($return) ? base64_decode($return) : ''; $fields = $model->getFields(); // include plugin spambotcheck if (isset($visform->spambotcheck) && $visform->spambotcheck == 1) { JPluginHelper::importPlugin('visforms'); $dispatcher = JDispatcher::getInstance(); $results = $dispatcher->trigger('onVisformsSpambotCheck'); foreach ($results as $result) { if ($result === true) { //Show form again, keep values already typed in if ($url != "") { $this->setRedirect($url); return false; } else { $this->display(); return false; } } } } //Check that data is ok, in case that javascript may not work properly foreach ($fields as $field) { if (isset($field->isValid) && $field->isValid == false) { //we have at least one invalid field // Get the validation error messages. $errors = $model->getErrors(); // Push up the validation messages for ($i = 0, $n = count($errors); $i < $n; $i++) { if ($errors[$i] instanceof Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } //Show form again, keep values already typed in if ($url != "") { $this->setRedirect($url); return false; } else { $this->display(); return false; } } } // Captcha ok? if ($visform->captcha == 1) { include "components/com_visforms/captcha/securimage.php"; $img = new Securimage(); $img->namespace = 'form' . JFactory::getApplication()->input->getInt('id', 0); $valid = $img->check($_POST['recaptcha_response_field']); if ($valid == false) { JError::raiseWarning(0, JText::_("COM_VISFORMS_CODE_INVALID")); //Show form again, keep values already typed in if ($url != "") { $this->setRedirect($url); return false; } else { $this->display(); return false; } } } if ($visform->captcha == 2) { JPluginHelper::importPlugin('captcha'); $dispatcher = JDispatcher::getInstance(); $res = $dispatcher->trigger('onCheckAnswer', $_POST['recaptcha_response_field']); if (!$res[0]) { JError::raiseWarning(0, JText::_("COM_VISFORMS_CODE_INVALID")); //Show form again, keep values already typed in if ($url != "") { $this->setRedirect($url); return false; } else { $this->display(); return false; } } } JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); if (isset($_SESSION['vis_send_once' . $visform->id])) { unset($_SESSION['vis_send_once' . $visform->id]); } else { JError::raiseWarning(0, JText::_("COM_VISFORMS_CAN_SENT_ONLY_ONCE")); return false; } $securimage_code_value = 'securimage_code_value'; unset($securimage_code_value); //trigger before save event JPluginHelper::importPlugin('visforms'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onVisformsBeforeFormSave', array('com_visforms.form', &$visform, &$fields)); //save data to db if ($model->saveData() === false) { // Get the validation messages. $errors = $model->getErrors(); // Push up the validation messages for ($i = 0, $n = count($errors); $i < $n; $i++) { if ($errors[$i] instanceof Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } //Show form again, keep values already typed in if ($url != "") { $this->setRedirect($url); return false; } else { $this->display(); return false; } } if (isset($_SESSION['vis_cache_page_' . $visform->id])) { $cacheid = $_SESSION['vis_cache_page_' . $visform->id]; $cache = JFactory::getCache(); $cacheresult = $cache->remove($cacheid, 'page'); } //trigger after save event $dispatcher->trigger('onVisformsAfterFormSave', array('com_visforms.form', &$visform, &$fields)); $msg = JText::sprintf('COM_VISFORMS_FORM_SEND_SUCCESS', 1); if (isset($visform->redirecturl) && $visform->redirecturl != "") { $this->setRedirect($visform->redirecturl); } else { if ((isset($visform->redirecturl) == false || $visform->redirecturl == "") && (isset($visform->textresult) == true && $visform->textresult != "")) { $message = JHTMLVisforms::replacePlaceholder($visform, $visform->textresult); $app->setUserState('com_visforms.form' . $visform->id . '.message', $message); $this->setRedirect("index.php?option=com_visforms&view=visforms&layout=message&id=" . $visform->id); } else { $app->setUserState('com_visforms.form' . $visform->id . '.fields', null); $app->setUserState('com_visforms.form' . $visform->id, null); $this->setRedirect(JURI::base(), $msg); } } }
/** * Send Result Mail */ private function sendResultMail($visform) { $mail = JFactory::getMailer(); $mail->CharSet = "utf-8"; $mailBody = JText::_('COM_VISFORMS_FORM') . " : " . $visform->title . " [" . $visform->name . "]<br />"; $mailBody .= JText::_('COM_VISFORMS_REGISTERED_AT') . " " . date("Y-m-d H:i:s") . "<br /><br />"; $emailSender = ""; $n = count($visform->fields); //Add user inputs to mail for ($i = 0; $i < $n; $i++) { $field = $visform->fields[$i]; if ($field->typefield == 'email') { if (isset($field->dbValue)) { $emailSender = $field->dbValue; } } if (!(isset($field->isButton) && $field->isButton === true) && $field->typefield != 'fieldsep' && (!isset($field->isDisabled) || $field->isDisabled == false)) { if ($field->typefield == 'file' && isset($_FILES[$field->name]['name']) && $_FILES[$field->name]['name'] != '') { if (isset($field->file['filelink'])) { $fieldValue = $field->file['filelink']; } else { $fieldValue = $field->file['filepath']; } //Attach file to email if ($field->file['filepath'] != "" && $visform->emailresultincfile == "1") { $mail->addAttachment($field->file['filepath']); } } else { if (isset($field->dbValue)) { $fieldValue = $field->dbValue; } else { $fieldValue = ''; } } if ($field->typefield == 'email') { $fieldValue = '<a href="mailto:' . $fieldValue . '">' . $fieldValue . '</a>'; } $mailBody .= $field->label . " : " . $fieldValue . "<br />"; } } $mailBody .= JText::_('COM_VISFORMS_IP_ADDRESS') . " : " . $_SERVER['REMOTE_ADDR'] . "<br />"; $articleid = $this->input->get('articleid'); if (isset($articleid) && $articleid != '') { $mailBody .= JText::_('COM_VISFORMS_ARTICLE_ID') . " : " . $articleid . "<br />"; } if (strcmp($visform->emailto, "") != 0) { $mail->addRecipient(explode(",", $visform->emailto)); } if (strcmp($visform->emailcc, "") != 0) { $mail->addCC(explode(",", $visform->emailcc)); } if (strcmp($visform->emailbcc, "") != 0) { $mail->addBCC(explode(",", $visform->emailbcc)); } $mail->setSender(array($visform->emailfrom, $visform->emailfromname)); $subject = JHTMLVisforms::replacePlaceholder($visform, $visform->subject); $mail->setSubject($subject); if ($emailSender != "") { $mail->addReplyTo($emailSender); } $mail->IsHTML(true); $mail->Encoding = 'base64'; $mail->setBody($mailBody); JPluginHelper::importPlugin('visforms'); $dispatcher = JDispatcher::getInstance(); $dispatcher->trigger('onVisformsEmailPrepare', array('com_visforms.form.resultmail', &$mail, $visform)); $sent = $mail->Send(); }