コード例 #1
0
ファイル: form.php プロジェクト: harshzalavadiya/fatak
 /**
  * Process and render the form with HTML output.
  *
  * @param bool $fieldsOnly
  * @return string html
  */
 public function getFormHtml($fieldsOnly = false)
 {
     // if no form was loaded return empty string
     if (empty($this->form)) {
         return '';
     }
     $fields_html = array();
     $view = new AView($this->registry, 0);
     foreach ($this->fields as $field) {
         $data = array('type' => HtmlElementFactory::getElementType($field['element_type']), 'name' => $field['field_name'], 'form' => $this->form['form_name'], 'attr' => $field['attributes'], 'required' => $field['required'], 'value' => $field['value'], 'options' => $field['options']);
         switch ($data['type']) {
             case 'multiselectbox':
                 $data['name'] .= '[]';
                 break;
             case 'checkboxgroup':
                 $data['name'] .= '[]';
                 break;
             case 'captcha':
                 $data['captcha_url'] = $this->html->getURL('common/captcha');
                 break;
         }
         $item = HtmlElementFactory::create($data);
         switch ($data['type']) {
             case 'IPaddress':
             case 'hidden':
                 $fields_html[$field['field_id']] = $item->getHtml();
                 break;
             default:
                 $view->batchAssign(array('element_id' => $item->element_id, 'title' => $field['name'], 'description' => !empty($this->form['description']) ? $field['description'] : '', 'error' => !empty($this->errors[$field['field_name']]) ? $this->errors[$field['field_name']] : '', 'item_html' => $item->getHtml()));
                 $fields_html[$field['field_id']] = $view->fetch('form/form_field.tpl');
         }
     }
     $output = '';
     if (!empty($this->groups)) {
         foreach ($this->groups as $group) {
             $view->batchAssign(array('group' => $group, 'fields_html' => $fields_html));
             $output .= $view->fetch('form/form_group.tpl');
         }
     } else {
         $view->batchAssign(array('fields_html' => $fields_html));
         $output .= $view->fetch('form/form_no_group.tpl');
     }
     // add submit button and form open/close tag
     if (!$fieldsOnly) {
         $data = array('type' => 'submit', 'form' => $this->form['form_name'], 'name' => $this->language->get('button_continue'), 'icon' => 'icon-arrow-right');
         $submit = HtmlElementFactory::create($data);
         $data = array('type' => 'form', 'name' => $this->form['form_name'], 'attr' => ' class="form" ', 'action' => $this->html->getSecureURL($this->form['controller'], '&form_id=' . $this->form['form_id'], true));
         $form_open = HtmlElementFactory::create($data);
         $form_close = $view->fetch('form/form_close.tpl');
         $js = $this->addFormJs();
         $view->batchAssign(array('description' => $this->form['description'], 'form' => $output, 'form_open' => $js . $form_open->getHtml(), 'form_close' => $form_close, 'submit' => $submit->getHtml()));
         $output = $view->fetch('form/form.tpl');
     }
     return $output;
 }
コード例 #2
0
 /**
  * Process and render the form with HTML output.
  *
  * @param bool $fieldsOnly
  * @return string html
  */
 public function getFormHtml($fieldsOnly = false)
 {
     // if no form was loaded return empty string
     if (empty($this->form)) {
         return '';
     }
     $fields_html = array();
     $view = new AView($this->registry, 0);
     foreach ($this->fields as $field) {
         //check for enabled recaptcha instead of default captcha
         if ($this->config->get('config_recaptcha_site_key') && $field['element_type'] == 'K') {
             $field['element_type'] = 'J';
         }
         //build data array for each field HTML template
         $data = array('type' => HtmlElementFactory::getElementType($field['element_type']), 'name' => $field['field_name'], 'form' => $this->form['form_name'], 'attr' => $field['attributes'], 'required' => $field['required'], 'value' => $field['value'], 'options' => $field['options']);
         //populate customer entered values from session (if present)
         if (is_array($this->session->data['custom_form_' . $this->form['form_id']])) {
             $data['value'] = $this->session->data['custom_form_' . $this->form['form_id']][$field['field_name']];
         }
         //custom data based on the HTML element type
         switch ($data['type']) {
             case 'multiselectbox':
                 $data['name'] .= '[]';
                 break;
             case 'checkboxgroup':
                 $data['name'] .= '[]';
                 break;
             case 'captcha':
                 $data['captcha_url'] = $this->html->getURL('common/captcha');
                 break;
             case 'recaptcha':
                 $data['recaptcha_site_key'] = $this->config->get('config_recaptcha_site_key');
                 $data['language_code'] = $this->language->getLanguageCode();
                 break;
         }
         $item = HtmlElementFactory::create($data);
         switch ($data['type']) {
             case 'IPaddress':
             case 'hidden':
                 $fields_html[$field['field_id']] = $item->getHtml();
                 break;
             default:
                 $view->batchAssign(array('element_id' => $item->element_id, 'type' => $data['type'], 'title' => $field['name'], 'description' => !empty($field['description']) ? $field['description'] : '', 'error' => !empty($this->errors[$field['field_name']]) ? $this->errors[$field['field_name']] : '', 'item_html' => $item->getHtml()));
                 $fields_html[$field['field_id']] = $view->fetch('form/form_field.tpl');
         }
     }
     $output = '';
     if (!empty($this->groups)) {
         foreach ($this->groups as $group) {
             $view->batchAssign(array('group' => $group, 'fields_html' => $fields_html));
             $output .= $view->fetch('form/form_group.tpl');
         }
     } else {
         $view->batchAssign(array('fields_html' => $fields_html));
         $output .= $view->fetch('form/form_no_group.tpl');
     }
     // add submit button and form open/close tag
     if (!$fieldsOnly) {
         $data = array('type' => 'submit', 'form' => $this->form['form_name'], 'name' => $this->language->get('button_submit'));
         $submit = HtmlElementFactory::create($data);
         $data = array('type' => 'form', 'name' => $this->form['form_name'], 'attr' => ' class="form" ', 'action' => $this->html->getSecureURL($this->form['controller'], '&form_id=' . $this->form['form_id'], true));
         $form_open = HtmlElementFactory::create($data);
         $form_close = $view->fetch('form/form_close.tpl');
         $js = $this->addFormJs();
         $view->batchAssign(array('description' => $this->form['description'], 'form' => $output, 'form_open' => $js . $form_open->getHtml(), 'form_close' => $form_close, 'submit' => $submit));
         $output = $view->fetch('form/form.tpl');
     }
     return $output;
 }