Skip to content

Instantly share code, notes, and snippets.

@themusicman
Created March 14, 2012 14:38
Show Gist options
  • Save themusicman/2036924 to your computer and use it in GitHub Desktop.
Save themusicman/2036924 to your computer and use it in GitHub Desktop.
EE2 Template Form Class
<?php
class Toolbox_Template_Form {
protected $form_html = NULL;
protected $tagdata = '';
protected $options = array();
/**
* __construct
*
* @access public
* @param void
* @return void
*
**/
public function __construct($tagdata, $options = array())
{
$this->EE = get_instance();
$this->tagdata = $tagdata;
$this->options = $options;
}
/**
* build
*
* @access protected
* @param void
* @return void
*
**/
protected function build()
{
if ($this->form_html === NULL)
{
$module_name = Arr::get($this->options, 'module_name');
$action_method = Arr::get($this->options, 'action');
if (strpos($action_method, '/') !== FALSE)
{
$action = '/' . trim($action_method, '/') . '/';
}
else
{
$action = ($action_method) ? '?ACT='.$this->EE->functions->fetch_action_id($module_name, $action_method) : "";
}
$hidden_fields = array(
'return' => Arr::get($this->options, 'return'),
'required' => Arr::get($this->options, 'required'),
'form_name' => Arr::get($this->options, 'form_name'),
'notify' => Arr::get($this->options, 'notify'),
);
$form_data = array(
'hidden_fields' => $hidden_fields,
'action' => $this->EE->config->item('site_url').$action,
'name' => Arr::get($this->options, 'form_name'),
'id' => Arr::get($this->options, 'form_id'),
);
$enctype = Arr::get($this->options, 'enctype');
if ($enctype)
{
$form_data['enctype'] = $enctype;
}
$this->form_html = $this->EE->functions->form_declaration($form_data);
$this->form_html .= stripslashes($this->tagdata);
$this->form_html .= "</form>";
}
}
/**
* method
*
* @access public
* @param void
* @return void
*
**/
public function __toString()
{
$this->build();
return $this->form_html;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment