本文整理汇总了PHP中HtmlElementFactory::getElementType方法的典型用法代码示例。如果您正苦于以下问题:PHP HtmlElementFactory::getElementType方法的具体用法?PHP HtmlElementFactory::getElementType怎么用?PHP HtmlElementFactory::getElementType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlElementFactory
的用法示例。
在下文中一共展示了HtmlElementFactory::getElementType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFormHtml
/**
* 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: getFormHtml
/**
* 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;
}