示例#1
0
 function loadAction($form, $actiondata)
 {
     $params = new JParameter($actiondata->params);
     $output = '';
     $mainframe =& JFactory::getApplication();
     $uri =& JFactory::getURI();
     $document =& JFactory::getDocument();
     if ((int) $form->form_params->get('load_files', 1) > 0) {
         //load form css files
         $CF_PATH = $mainframe->isSite() ? JURI::Base() : $uri->root();
         if ((int) $form->form_params->get('tight_layout', 0) == 0) {
             $document->addStyleSheet($CF_PATH . 'components/com_chronoforms/css/frontforms.css');
         } else {
             $document->addStyleSheet($CF_PATH . 'components/com_chronoforms/css/frontforms_tight.css');
         }
     }
     if (($form->form_params->get('enable_jsvalidation', 1) || strpos($form->form_details->content, 'validate[') !== false && $form->form_params->get('auto_detect_settings', 1)) && (int) $form->form_params->get('load_files', 1) > 0) {
         //load js validation code
         $this->_loadValidationScripts($form);
     }
     $datetime_picker_selector = $form->form_params->get('datepicker_config', '');
     if ((!empty($datetime_picker_selector) || strpos($form->form_details->content, 'cf_date_picker') !== false || strpos($form->form_details->content, 'cf_time_picker') !== false || strpos($form->form_details->content, 'cf_datetime_picker') !== false) && (int) $form->form_params->get('load_files', 1) > 0) {
         //load js for the date time picker
         $this->_loadDatePickerScripts($form);
     }
     if (strpos($form->form_details->content, 'tooltipimg') !== false && (int) $form->form_params->get('load_files', 1) > 0) {
         //load the tooltips files
         $this->_loadToolTip($form);
     }
     if (!empty($form->validation_errors) && (int) $form->form_params->get('load_files', 1) > 0) {
         //add the validation style
         $this->_loadSSValidation($form);
     }
     //check if form tags should be added or not
     if ($form->form_params->get('add_form_tags', 1)) {
         $output .= "<form ";
         $form_tag_array = array();
         if (trim($form->form_params->get('action_url', ''))) {
             $form_tag_array[] = 'action="' . $form->form_params->get('action_url', '') . '"';
         } else {
             $action_url = 'index.php?option=com_chronoforms&amp;chronoform=' . $form->form_name;
             if ($form->form_params->get('relative_url', 1) == 1) {
                 $action_url = $this->selfURL();
                 preg_match_all('/(&*)event=([^&]+)/is', $action_url, $event_matches);
                 $action_url = str_replace($event_matches[0], '', $action_url);
                 //strip the form name if exists and add own form name
                 preg_match_all('/(&*)chronoform=([^&]+)/is', $action_url, $chronoform_matches);
                 $action_url = str_replace($chronoform_matches[0], '', $action_url);
                 $separator = $this->_getURLSeparator($action_url);
                 $action_url .= $separator . 'chronoform=' . $form->form_name;
             }
             if ($form->form_params->get('submit_action', 'submit') != 'self') {
                 $separator = $this->_getURLSeparator($action_url);
                 $action_url .= $separator . 'event=' . $form->form_params->get('submit_action', 'submit');
             }
             //attach the itemid if exists
             $item_id = JRequest::getVar('Itemid', '');
             if (!empty($item_id) && stripos($this->selfURL(), 'Itemid') !== false && strpos($action_url, 'Itemid') === false) {
                 $separator = $this->_getURLSeparator($action_url);
                 $action_url .= $separator . 'Itemid=' . $item_id;
             }
             $form_tag_array[] = 'action="' . $action_url . '"';
         }
         $form_tag_array[] = 'name="' . $form->form_name . '"';
         $form_tag_array[] = 'id="chronoform_' . $form->form_name . '"';
         $enctype = '';
         $method = $form->form_params->get('form_method', 'post');
         if ($method == 'file' || $form->form_params->get('auto_detect_settings', 1) && (stripos($form->form_details->content, 'type="file"') !== false || stripos($form->form_details->content, "type='file'") !== false)) {
             $method = 'post';
             $enctype = 'enctype="multipart/form-data"';
         }
         //add the form method
         $form_tag_array[] = 'method="' . $method . '"';
         //add the enctype if exists
         $form_tag_array[] = $enctype;
         //add the form class
         $form_tag_array[] = 'class="Chronoform"';
         //add any attachments
         if (trim($form->form_params->get('form_tag_attach', ''))) {
             $form_tag_array[] = $form->form_params->get('form_tag_attach', '');
         }
         //build the form tag
         $output .= implode(" ", array_filter($form_tag_array)) . '>';
         //$output .= $this->Form->create('ChronoformData', array('url' => $action_url, 'id' => 'ChronoForm_'.$formdetails['Chronoform']['name'], 'type' => 'file', 'class' => 'Chronoform'));
     }
     //show error messages
     $this->_showErrors($form);
     //echo $output;
     ob_start();
     eval('?>' . $form->form_details->content);
     $output .= ob_get_clean();
     //Load any form data
     if ((int) $params->get('data_republish', 1) == 1) {
         include_once JPATH_SITE . DS . 'components' . DS . 'com_chronoforms' . DS . 'libraries' . DS . 'includes' . DS . 'data_republish.php';
         $HTMLFormPostDataLoad = new HTMLFormPostDataLoad();
         //$HTMLFormPostDataLoad->validation_errors = $form->validation_errors;
         if (isset($form->data['chrono_verification']) && !empty($form->data['chrono_verification'])) {
             $form->data['chrono_verification'] = '';
         }
         $output = $HTMLFormPostDataLoad->load($output, $form->data);
     }
     //Display any form errors
     if ((int) $params->get('display_errors', 1) == 1) {
         include_once JPATH_SITE . DS . 'components' . DS . 'com_chronoforms' . DS . 'libraries' . DS . 'includes' . DS . 'display_errors.php';
         $HTMLFormPostDisplayErrors = new HTMLFormPostDisplayErrors();
         $HTMLFormPostDisplayErrors->validation_errors = $form->validation_errors;
         $output = $HTMLFormPostDisplayErrors->load($output, $form->data);
     }
     //Replace curly fields names
     if ((int) $params->get('curly_replacer', 1) == 1) {
         $output = $form->curly_replacer($output, $form->data);
     }
     //load token if enabled
     if ((int) $params->get('load_token', 1) == 1) {
         $output .= JHTML::_('form.token');
     }
     //load keep alive if enabled
     if ((int) $params->get('keep_alive', 0) == 1) {
         JHTML::_('behavior.keepalive');
     }
     //$output = '';
     //check if form tags should be added or not
     if ($form->form_params->get('add_form_tags', 1)) {
         $output .= "</form>";
     }
     echo $output;
 }
 function loadAction($form, $actiondata)
 {
     $params = new JParameter($actiondata->params);
     $output = '';
     $mainframe =& JFactory::getApplication();
     $uri =& JFactory::getURI();
     $document =& JFactory::getDocument();
     //set form's HTML name and ID
     $form->html_form_name = isset($form->html_form_name) ? $form->html_form_name : $form->form_params->get('html_form_name', $form->form_name);
     $form->html_form_id = isset($form->html_form_id) ? $form->html_form_id : $form->form_params->get('html_form_id', 'chronoform_' . $form->form_name);
     //check the assets files to be loaded
     if ((int) $form->form_params->get('load_files', 1) > 0) {
         //load form css files
         if ((bool) $form->form_params->get('tight_layout', 0) === false) {
             $document->addStyleSheet($uri->root() . 'components/com_chronoforms/css/frontforms.css');
         } else {
             $document->addStyleSheet($uri->root() . 'components/com_chronoforms/css/frontforms_tight.css');
         }
     }
     if (($form->form_params->get('enable_jsvalidation', 1) || strpos($form->form_details->content, 'validate[') !== false && $form->form_params->get('auto_detect_settings', 1)) && (int) $form->form_params->get('load_files', 1) > 0) {
         //load js validation code
         $this->_loadValidationScripts($form);
     }
     $datetime_picker_selector = $form->form_params->get('datepicker_config', '');
     if ((!empty($datetime_picker_selector) || strpos($form->form_details->content, 'cf_date_picker') !== false || strpos($form->form_details->content, 'cf_time_picker') !== false || strpos($form->form_details->content, 'cf_datetime_picker') !== false) && (int) $form->form_params->get('load_files', 1) > 0) {
         //load js for the date time picker
         $jversion = new JVersion();
         if ($jversion->RELEASE > 1.5 && $form->form_params->get('datepicker_type', 0) == 1) {
             $this->_loadDatePickerScripts_moo($form);
         } else {
             $this->_loadDatePickerScripts($form);
         }
     }
     if (strpos($form->form_details->content, 'tooltipimg') !== false && (int) $form->form_params->get('load_files', 1) > 0) {
         //load the tooltips files
         $this->_loadToolTip($form);
     }
     if (!empty($form->validation_errors) && (int) $form->form_params->get('load_files', 1) > 0) {
         //add the validation style
         $this->_loadSSValidation($form);
     }
     //check if form tags should be added or not
     if ($form->form_params->get('add_form_tags', 1)) {
         $output .= "<form ";
         $form_tag_array = array();
         if (trim($form->form_params->get('action_url', ''))) {
             $form_tag_array[] = 'action="' . $form->form_params->get('action_url', '') . '"';
         } else {
             $action_url = 'index.php?option=com_chronoforms&amp;chronoform=' . $form->form_name;
             if ($form->form_params->get('relative_url', 1) == 1) {
                 $action_url = $this->selfURL();
                 if ((bool) $form->disguised === true) {
                     //disguise mode, the event will be used as a task for the parent app
                     preg_match_all('/(&*)task=([^&]+)/is', $action_url, $chronoform_matches);
                     $action_url = str_replace($chronoform_matches[0], '', $action_url);
                     $separator = $this->_getURLSeparator($action_url);
                     if (isset($form->data['task']) && !empty($form->data['task']) && strpos($action_url, $form->data['task']) !== false) {
                         //this is propably a SEF URL
                         $action_url = str_replace($form->data['task'], $form->form_params->get('action_task', $params->get('submit_event', 'submit')), $action_url);
                     } else {
                         $action_url .= $separator . 'task=' . $form->form_params->get('action_task', $params->get('submit_event', 'submit'));
                     }
                 } else {
                     preg_match_all('/(&*)event=([^&]+)/is', $action_url, $event_matches);
                     $action_url = str_replace($event_matches[0], '', $action_url);
                     //strip the form name if exists and add own form name
                     preg_match_all('/(&*)chronoform=([^&]+)/is', $action_url, $chronoform_matches);
                     $action_url = str_replace($chronoform_matches[0], '', $action_url);
                     $separator = $this->_getURLSeparator($action_url);
                     $action_url .= $separator . 'chronoform=' . $form->form_name;
                 }
             }
             if ((bool) $form->disguised === false) {
                 $separator = $this->_getURLSeparator($action_url);
                 $action_url .= $separator . 'event=' . $params->get('submit_event', 'submit');
             }
             //attach the itemid if exists
             $item_id = JRequest::getVar('Itemid', '');
             if (!empty($item_id) && stripos($this->selfURL(), 'Itemid') !== false && strpos($action_url, 'Itemid') === false) {
                 $separator = $this->_getURLSeparator($action_url);
                 $action_url .= $separator . 'Itemid=' . $item_id;
             }
             //attach the session id if it exists in the data array
             $session_key_param = $form->form_params->get('session_key_param', 'cf_sid');
             //if(isset($form->data[$session_key_param]) && !empty($form->data[$session_key_param])){
             if (isset($form->session_token) && !empty($form->session_token)) {
                 preg_match_all('/(&*)' . $session_key_param . '=([^&]+)/is', $action_url, $session_key_param_matches);
                 $action_url = str_replace($session_key_param_matches[0], '', $action_url);
                 $separator = $this->_getURLSeparator($action_url);
                 $action_url .= $separator . $session_key_param . '=' . $form->session_token;
             }
             //fix the ampersand
             $action_url = str_replace('&amp;', '&', $action_url);
             $action_url = str_replace('&&', '&', $action_url);
             $action_url = str_replace('&', '&amp;', $action_url);
             //add the action URL to the form tag pieces array
             $form_tag_array[] = 'action="' . $action_url . '"';
         }
         $form_tag_array[] = 'name="' . $form->html_form_name . '"';
         $form_tag_array[] = 'id="' . $form->html_form_id . '"';
         $enctype = '';
         $method = $form->form_params->get('form_method', 'post');
         if ($method == 'file' || $form->form_params->get('auto_detect_settings', 1) && (stripos($form->form_details->content, 'type="file"') !== false || stripos($form->form_details->content, "type='file'") !== false)) {
             $method = 'post';
             $enctype = 'enctype="multipart/form-data"';
         }
         //add the form method
         $form_tag_array[] = 'method="' . $method . '"';
         //add the enctype if exists
         $form_tag_array[] = $enctype;
         //add the form class
         $form_tag_array[] = 'class="Chronoform' . $form->form_params->get('html_form_class', '') . '"';
         //add any attachments
         if (trim($form->form_params->get('form_tag_attach', ''))) {
             $form_tag_array[] = $form->form_params->get('form_tag_attach', '');
         }
         //build the form tag
         $output .= implode(" ", array_filter($form_tag_array)) . '>';
     }
     //show error messages
     $this->_showErrors($form);
     //echo $output;
     ob_start();
     eval('?>' . $form->form_details->content);
     $temp_output = ob_get_clean();
     //check the page to view
     if (preg_match("/<!--_CHRONOFORMS_PAGE_BREAK_-->/i", $temp_output)) {
         $form_pages = explode("<!--_CHRONOFORMS_PAGE_BREAK_-->", $temp_output);
         $active_page_index = (int) $params->get('page_number', 1) - 1;
         $output .= $form_pages[$active_page_index];
     } else {
         $output .= $temp_output;
     }
     //add any extra content
     $output .= $form->extra_content;
     //Load any form data
     if ((int) $params->get('data_republish', 1) == 1) {
         include_once JPATH_SITE . DS . 'components' . DS . 'com_chronoforms' . DS . 'libraries' . DS . 'includes' . DS . 'data_republish.php';
         $HTMLFormPostDataLoad = new HTMLFormPostDataLoad();
         //$HTMLFormPostDataLoad->validation_errors = $form->validation_errors;
         if (isset($form->data['chrono_verification']) && !empty($form->data['chrono_verification'])) {
             $form->data['chrono_verification'] = '';
         }
         $output = $HTMLFormPostDataLoad->load($output, $form->data);
     }
     //Display any form errors
     if ((int) $params->get('display_errors', 1) == 1) {
         include_once JPATH_SITE . DS . 'components' . DS . 'com_chronoforms' . DS . 'libraries' . DS . 'includes' . DS . 'display_errors.php';
         $HTMLFormPostDisplayErrors = new HTMLFormPostDisplayErrors();
         $HTMLFormPostDisplayErrors->validation_errors = $form->validation_errors;
         $output = $HTMLFormPostDisplayErrors->load($output, $form->data);
     }
     //Replace curly fields names
     if ((int) $params->get('curly_replacer', 1) == 1) {
         $output = $form->curly_replacer($output, $form->data, '.', true);
     }
     //load token if enabled
     if ((int) $params->get('load_token', 1) == 1) {
         $output .= JHTML::_('form.token');
     }
     //load keep alive if enabled
     if ((int) $params->get('keep_alive', 0) == 1) {
         JHTML::_('behavior.keepalive');
     }
     //check if form tags should be added or not
     if ($form->form_params->get('add_form_tags', 1)) {
         $output .= "</form>";
     }
     //check if the form should be inside a div container ?
     if (strlen(trim($params->get('form_container', ''))) > 0) {
         $output = '<div id="' . trim($params->get('form_container', '')) . '">' . $output . '</div>';
     }
     echo $output;
 }