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 onload($option, $row, $params, $html_string)
 {
     global $mainframe;
     $my = JFactory::getUser();
     $db =& JFactory::getDBO();
     $session =& JFactory::getSession();
     //get chrono instances
     $formname = JRequest::getVar('chronoformname');
     $MyForm =& CFChronoForm::getInstance($formname);
     $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
     $MyCustomCode =& CFCustomCode::getInstance($MyForm->formrow->id);
     $MyPlugins =& CFPlugins::getInstance($MyForm->formrow->id);
     $chrono_next_step = $session->get('chrono_next_step', '', md5('chrono'));
     if (JRequest::getVar('task') != 'beforeshow') {
         $session->set("chrono_next_step", '', md5('chrono'));
     }
     if ($chrono_next_step == 'confirm') {
         if (!JRequest::checkToken() && $MyForm->formparams('checkToken', 1)) {
             echo "You are not allowed to access this URL";
             return;
         }
         $html_string = '';
         $posted = JRequest::get('post', JREQUEST_ALLOWRAW);
         if (JRequest::getVar('confirm') == trim($params->get('submit_button_value', 'Submit'))) {
             $debug = $MyForm->formparams('debug');
             //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 != 0 && !$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';
             }
             $html_string = '';
         } else {
             $session->set("chrono_next_step", '', md5('chrono'));
             $MyForm->showForm($MyForm->formrow->name, $posted);
             $MyForm->stoploading = true;
             return;
             $html_string = '';
         }
     }
     return $html_string;
 }
 function onsubmit($option, $params, $row)
 {
     global $mainframe;
     $database =& JFactory::getDBO();
     $pluginrow = $row;
     $posted = JRequest::get('post', JREQUEST_ALLOWRAW);
     $formname = JRequest::getVar('chronoformname');
     $MyForm =& CFChronoForm::getInstance($formname);
     $MyFormEmails =& CFEMails::getInstance($MyForm->formrow->id);
     $MyCustomCode =& CFCustomCode::getInstance($MyForm->formrow->id);
     //save the data
     $posted[$params->get('vflagfield')] = 0;
     if (!empty($MyForm->formrow->autogenerated)) {
         eval("?>" . $MyForm->formrow->autogenerated);
     }
     //run the onsubmit before verification code
     if (!empty($pluginrow->extra2)) {
         eval("?>" . $pluginrow->extra2);
     }
     //send the verification email
     if ($params->get('subject')) {
         $subject = $params->get('subject');
     } else {
         $subject = $posted[$params->get('dsubject')];
     }
     if ($params->get('to')) {
         $recipients = $params->get('to');
     } else {
         $recipients = $posted[$params->get('dto')];
     }
     if ($params->get('fromname')) {
         $fromname = $params->get('fromname');
     } else {
         $fromname = $posted[$params->get('dfromname')];
     }
     if ($params->get('fromemail')) {
         $fromemail = $params->get('fromemail');
     } else {
         $fromemail = $posted[$params->get('dfromemail')];
     }
     $email_body = $pluginrow->extra1;
     foreach ($posted as $key => $value) {
         $email_body = str_replace("{" . $key . "}", $value, $email_body);
     }
     //global ${'row_'.$params->get('vtablename')};
     $vlink = JURI::Base() . 'index.php?option=com_chronocontact&amp;chronoformname=' . $formname . '&amp;task=beforeshow&amp;uid=' . $MyForm->tablerow[$params->get('vtablename')]->uid;
     $vlink = '<a target="_blank" href="' . $vlink . '">' . $vlink . '</a>';
     $email_body = str_replace("{vlink}", $vlink, $email_body);
     //echo $email_body;
     JUtility::sendMail($fromemail, $fromname, $recipients, $subject, $email_body, true);
     //exit the form routine
     $MyForm->stoprunning = true;
     return;
 }