function submitForm($formname, $posted = array(), $useCurrent = false) { global $mainframe; $database =& JFactory::getDBO(); if (empty($posted)) { $posted = JRequest::get('post', JREQUEST_ALLOWRAW); } if ($useCurrent) { $MyForm = $this->getInstance($formname); } else { $MyForm =& CFChronoForm::getInstance($formname); } $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id); $MyCustomCode =& CFCustomCode::getInstance($MyForm->formrow->id); $MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id); $MyForm->posted = $posted; $debug = $MyForm->formparams('debug'); $MyForm->addDebugMsg('Form passed first SPAM check OK'); $session =& JFactory::getSession(); // Check how soon was the last submission $MyForm->checkSubmissionsLimit($MyForm->formrow->name); $MyForm->addDebugMsg('Form passed the submissions limit (if enabled) OK'); /** * If imageversification is on check the code */ $MyForm->checkImageVerification($MyForm->formrow->name); $MyForm->addDebugMsg('Form passed the Image verification (if enabled) OK'); //Server side validation $MyForm->checkServerValidation($MyForm->formrow->name); $MyForm->addDebugMsg('Form passed the server side validation (if enabled) OK'); //if any check steps failed, quit and reshow the form if ($MyForm->showFormErrors($MyForm->formrow->name)) { $MyForm->showForm($MyForm->formrow->name, $posted); return; } /** * if $debug is true then ChronoForms will show diagnostic output */ $MyForm->addDebugMsg("\$_POST Array: " . print_r($posted, true)); $MyForm->addDebugMsg("\$_FILES Array: " . print_r($_FILES, true)); /** * Upload attachments */ if (!$MyForm->haltFunction["uploads"]) { $MyUploads =& CFUploads::getInstance($MyForm->formrow->id); $MyUploads->handleUploads(); //show errors if any if ($MyForm->showFormErrors($MyForm->formrow->name)) { $MyForm->showForm($MyForm->formrow->name, $posted); return; } } /* Do Onsubmit before_email plugins*/ if (!$MyForm->haltFunction["plugins_before_email"]) { $MyPlugins->runPlugin('before_email'); $MyForm->addDebugMsg('Form passed the plugins step (if enabled) OK'); //show errors if any if ($MyForm->showFormErrors($MyForm->formrow->name)) { $MyForm->showForm($MyForm->formrow->name, $posted); return; } } //handle arrays $MyForm->handleArrays($MyForm->formrow->name); /** * If there are no errors and e-mail is required then build and send it. */ if ($MyForm->formrow->emailresults && !$MyForm->error_found && !$MyForm->stoprunning) { //run before submit code if (!$MyForm->haltFunction["onsubmitcodeb4"]) { $MyCustomCode->runCode('onsubmitcodeb4'); if ($MyForm->showFormErrors($MyForm->formrow->name)) { $MyForm->showForm($MyForm->formrow->name, $posted); return; } } if (!$MyForm->haltFunction["autogenerated_before_email"]) { $MyCustomCode->runCode('autogenerated', 'before_email'); } //send emails if (!$MyForm->haltFunction["emails"]) { $emails_result = $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails); } } if (!$MyForm->error_found && !$MyForm->stoprunning) { /*************** check to see if order was specified, if not then use the default old one ************************/ if (!$MyForm->formparams('plugins_order') && !$MyForm->formparams('onsubmitcode_order') && !$MyForm->formparams('autogenerated_order')) { $MyForm->setFormParam('autogenerated_order', 3); $MyForm->setFormParam('onsubmitcode_order', 2); $MyForm->setFormParam('plugins_order', 1); } for ($ixx = 1; $ixx <= 3; $ixx++) { if ($MyForm->formparams('plugins_order') == $ixx) { if (!$MyForm->haltFunction["plugins_after_email"]) { $MyPlugins->runPlugin('after_email'); //show errors if any if ($MyForm->showFormErrors($MyForm->formrow->name)) { $MyForm->showForm($MyForm->formrow->name, $posted); return; } } } /** * Run the On-submit 'post e-mail' code if there is any */ if ($MyForm->formparams('onsubmitcode_order') == $ixx) { if (!$MyForm->haltFunction["onsubmitcode"]) { $MyCustomCode->runCode('onsubmitcode'); if ($MyForm->showFormErrors($MyForm->formrow->name)) { $MyForm->showForm($MyForm->formrow->name, $posted); return; } } } /** * Run the SQL query if there is one */ if ($MyForm->formparams('autogenerated_order') == $ixx) { if (!$MyForm->haltFunction["autogenerated_after_email"]) { $MyCustomCode->runCode('autogenerated', 'after_email'); } } } //Mark submission as complete! $MyForm->submission_complete = true; $MyForm->addDebugMsg('Debug End'); /** * Redirect the page if requested */ if (!empty($MyForm->formrow->redirecturl)) { if (!$debug) { $mainframe->redirect($MyForm->formrow->redirecturl); } else { $MyForm->addDebugMsg("<div class='debug' >Redirect link set, click to test:<br /><a href='" . $MyForm->formrow->redirecturl . "'>" . $MyForm->formrow->redirecturl . "</a></div>"); } } } if (!empty($MyForm->formdebug) && $MyForm->formparams('debug') == '1') { include_once JPATH_COMPONENT . DS . 'libraries' . DS . 'includes' . DS . 'Debug.php'; } }
function sendEmails($MyForm, $emails, $posted = array()) { global $mainframe; $database =& JFactory::getDBO(); if (!count($posted)) { $posted = JRequest::get('post', JREQUEST_ALLOWRAW); } /** * Associate field values with names and implode arrays */ $fields = array(); $fields = $MyForm->handleArrays($MyForm->formrow->name); //loop emails foreach ($emails as $email) { $email_params = new JParameter($email->params); if ($email->enabled == "1") { $email_body = $email->template; ob_start(); eval("?>" . $email_body); $email_body = ob_get_clean(); //build email template from defined fields and posted fields foreach ($posted as $name => $post) { if (!is_array($post)) { $post = nl2br((string) $post); $email_body = str_replace("{" . $name . "}", $post, $email_body); } else { $email_body = str_replace("{" . $name . "}", implode(", ", $post), $email_body); } } foreach ($fields as $name => $post) { $email_body = str_replace("{" . $name . "}", $post, $email_body); } /** * Add IP address if required */ if ($email_params->get('recordip', "1") == "1") { if (!ereg("\\{IPADDRESS\\}", $email_body)) { if ($email_params->get('emailtype', "html") == "html") { $email_body .= "<br /><br />"; } $email_body .= "\nSubmitted by {IPADDRESS}"; } $email_body = str_replace('{IPADDRESS}', $_SERVER['REMOTE_ADDR'], $email_body); } $this->emailsbodies[] = $email_body; /** * Wrap page code around the html message body */ if ($email_params->get('emailtype', "html") == "html") { $email_body = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n\t\t\t\t\t <html>\n\t\t\t\t\t\t <head>\n\t\t\t\t\t\t\t<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n\t\t\t\t\t\t\t<base href=\"" . JURI::base() . "/\" />\n\t\t\t\t\t\t\t<title>Email</title>\n\t\t\t\t\t\t </head>\n\t\t\t\t\t\t \n\t\t\t\t\t\t <body>{$email_body}</body>\n\t\t\t\t\t </html>"; } $fromname = trim($email->fromname) ? trim($email->fromname) : $posted[trim($email->dfromname)]; $from = trim($email->fromemail) ? trim($email->fromemail) : $posted[trim($email->dfromemail)]; $subject = trim($email->subject) ? trim($email->subject) : $posted[trim($email->dsubject)]; // Recepients $recipients = array(); if (trim($email->to)) { $recipients = explode(",", trim($email->to)); } if (trim($email->dto)) { $dynamic_recipients = explode(",", trim($email->dto)); foreach ($dynamic_recipients as $dynamic_recipient) { if ($posted[trim($dynamic_recipient)]) { $recipients[] = $posted[trim($dynamic_recipient)]; } } } // CCs $ccemails = array(); if (trim($email->cc)) { $ccemails = explode(",", trim($email->cc)); } if (trim($email->dcc)) { $dynamic_ccemails = explode(",", trim($email->dcc)); foreach ($dynamic_ccemails as $dynamic_ccemail) { if ($posted[trim($dynamic_ccemail)]) { $ccemails[] = $posted[trim($dynamic_ccemail)]; } } } // BCCs $bccemails = array(); if (trim($email->bcc)) { $bccemails = explode(",", trim($email->bcc)); } if (trim($email->dbcc)) { $dynamic_bccemails = explode(",", trim($email->dbcc)); foreach ($dynamic_bccemails as $dynamic_bccemail) { if ($posted[trim($dynamic_bccemail)]) { $bccemails[] = $posted[trim($dynamic_bccemail)]; } } } // ReplyTo Names $replytonames = array(); if (trim($email->replytoname)) { $replytonames = explode(",", trim($email->replytoname)); } if (trim($email->dreplytoname)) { $dynamic_replytonames = explode(",", trim($email->dreplytoname)); foreach ($dynamic_replytonames as $dynamic_replytoname) { if ($posted[trim($dynamic_replytoname)]) { $replytonames[] = $posted[trim($dynamic_replytoname)]; } } } // ReplyTo Emails $replytoemails = array(); if (trim($email->replytoemail)) { $replytoemails = explode(",", trim($email->replytoemail)); } if (trim($email->dreplytoemail)) { $dynamic_replytoemails = explode(",", trim($email->dreplytoemail)); foreach ($dynamic_replytoemails as $dynamic_replytoemail) { if ($posted[trim($dynamic_replytoemail)]) { $replytoemails[] = $posted[trim($dynamic_replytoemail)]; } } } // Replies $replyto_email = $replytoemails; $replyto_name = $replytonames; $mode = $email_params->get('emailtype', "html") == 'html' ? true : false; if (!$mode) { $email_body = JFilterInput::clean($email_body, 'STRING'); } $this_attachments = array(); if ($email_params->get("enable_attachments", "1") == "1") { $MyUploads =& CFUploads::getInstance($MyForm->formrow->id); $this_attachments = $MyUploads->attachments; } else { $this_attachments = array(); } /** * Send the email(s) */ $email_sent = JUtility::sendMail($from, $fromname, $recipients, $subject, $email_body, $mode, $ccemails, $bccemails, $this_attachments, $replyto_email, $replyto_name); if ($email_sent) { $MyForm->addDebugMsg('An email has been SENT successfully from (' . $fromname . ')' . $from . ' to ' . implode(',', $recipients)); } if (!$email_sent) { $MyForm->addDebugMsg('An email has failed to be sent from (' . $fromname . ')' . $from . ' to ' . implode(',', $recipients)); } // :: HACK :: insert debug if ($MyForm->formparams('debug')) { echo "<h4>E-mail message</h4>\n\t\t\t\t\t<div style='border:1px solid black; padding:6px;margin:6px;'>\n\t\t\t\t\t<p>From: {$fromname} [{$from}]<br />\n\t\t\t\t\tTo: " . implode(', ', $recipients) . "<br />\n\t\t\t\t\tCC: " . implode(', ', $ccemails) . "<br />\n\t\t\t\t\tBCC: " . implode(', ', $bccemails) . "<br />\n\t\t\t\t\tSubject: {$subject}</p>\n\t\t\t\t\t{$email_body}<br /><br />\n\t\t\t\t\tFiles: " . implode(', ', $this_attachments) . "<br /></div>"; } } } return $emails; }
function onsubmit($option, $params, $row) { global $mainframe; //echo "XXX"; require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_chronocontact' . DS . 'helpers' . DS . 'plugin.php'; $helper = new ChronoContactHelperPlugin(); if ($row->form_id) { $formname = CFChronoForm::getFormName($row->form_id); } else { $formname = JRequest::getVar('chronoformname'); } $MyForm =& CFChronoForm::getInstance($formname); $MyUploads =& CFUploads::getInstance($MyForm->formrow->id); $session =& JFactory::getSession(); $pluginrow = $row; $newposted = JRequest::get('post', JREQUEST_ALLOWRAW); $oldposted = array(); if ($session->get('chrono_formpages_data_' . $formname, array(), md5('chrono'))) { $oldposted = $session->get('chrono_formpages_data_' . $formname, array(), md5('chrono')); } if ($session->get('chrono_formpages_files_' . $formname, array(), md5('chrono'))) { $MyUploads->attachments = $session->get('chrono_formpages_files_' . $formname, array(), md5('chrono')); } $posted = array_merge($oldposted, $newposted); $messages[] = 'Posted: ' . print_r($posted, true); $messages[] = 'Files: ' . print_r($MyUploads->attachments, true); JRequest::set($posted, 'post'); $session->set('chrono_formpages_data_' . $formname, $posted, md5('chrono')); $pages = explode(",", $params->get('formsnames')); $current_step = $session->get('chrono_step_' . $formname, '', md5('chrono')); $messages[] = 'Current step: ' . print_r($current_step, true); if ($params->get('debugging')) { $helper->showPluginDebugMessages($messages); } if (JRequest::getVar($params->get('finalbuttonname'))) { $current_step = 'end'; } if ($current_step != 'end') { if ($current_step) { $newForm =& CFChronoForm::getInstance(trim($pages[$current_step - 1])); $newForm->formrow->submiturl = $newForm->getAction($MyForm->formrow->name); $newForm->formrow->html = $newForm->formrow->html . '<input type="hidden" name="cfformstep" value="' . $current_step . '" />'; $newForm->submitForm($newForm->formrow->name, $posted); $newUploads =& CFUploads::getInstance($newForm->formrow->id); $MyUploads->attachments = array_merge($MyUploads->attachments, $newUploads->attachments); $session->set('chrono_formpages_files_' . $formname, $MyUploads->attachments, md5('chrono')); //check if the previous form submission completed successfully if ($newForm->submission_complete) { if ($current_step == (int) $params->get('stepscount')) { $session->set('chrono_step_' . $formname, 'end', md5('chrono')); //$MyForm->submitForm($MyForm->formrow->name); return; } $nextForm =& CFChronoForm::getInstance(trim($pages[$current_step])); $nextForm->formrow->submiturl = $nextForm->getAction($MyForm->formrow->name); $nextForm->formrow->html = $nextForm->formrow->html . '<input type="hidden" name="cfformstep" value="' . $current_step . '" />'; $session->set('chrono_step_' . $formname, $current_step + 1, md5('chrono')); $nextForm->showForm($nextForm->formrow->name, $posted); } } else { $newForm =& CFChronoForm::getInstance(trim($pages[0])); $newForm->formrow->submiturl = $newForm->getAction($MyForm->formrow->name); $session->set('chrono_step_' . $formname, 1, md5('chrono')); $newForm->showForm($newForm->formrow->name, $posted); } //exit the form routine $MyForm->stoprunning = true; return; } }