Created
March 14, 2012 14:38
-
-
Save themusicman/2036924 to your computer and use it in GitHub Desktop.
EE2 Template Form Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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