_hsc = $hsc; $this->_name = $name; $this->_key = md5(time().$name.FORM_SECRET); $this->errors = new Errors(); } function escapeAll() { if ($this->_hsc && !$this->_hsced) { foreach ($this->_vals as $key=>$val) { if (!is_array($val)) { $this->_vals[htmlspecialchars($key)] = htmlspecialchars($val); } else { foreach ($val as $k=>$v) { $this->_vals[htmlspecialchars($key)][htmlspecialchars($k)] = htmlspecialchars($v); } } } $this->_hsced = true; } } function setVals($vals) { $this->_vals = $vals; } function setPost($post) { $this->setVals($post); $this->_hsced = false; $this->escapeAll(); if (!isset($post['_key']) || $post['_key'] != $this->_key) { $this->errors->add('Sorry, this form has expired. Please re-submit your data in a timely manner. If you did not intend to submit this form, you may have been the victim of a CSRF attempt.'); } } function set($key,$val) { if ($this->_hsc) { $key = htmlspecialchars($key); if (!is_array($val)) { $this->_vals[$key] = htmlspecialchars($val); } else { $this->_vals[$key] = array(); foreach ($val as $v) { $this->_vals[$key][] = htmlspecialchars($v); } } } else { $this->_vals[$key] = $val; } } function get($key=NULL) { if ($key === NULL) { return $this->_vals; } else { if ($this->_hsc) { return $this->_vals[htmlspecialchars($key)]; } else { return $this->_vals[$key]; } } } function del($key) { if (isset($this->_vals[$key])) { unset($this->_vals[$key]); } } function save() { global $session; $session->set('form-'.$this->_name,$this); } function load($name) { global $session; if ($session->get('form-'.$name)) { return $session->get('form-'.$name); } else { return new Form($name); } } function clear() { global $session; $this->_vals = array(); if ($session->get('form-'.$this->_name) != null) { $session->delete('form-'.$this->_name); } } function setHsc($which=true) { $this->_hsc = $which; } // form inputs/*{{{*/ function inputText($name,$extras='') { return ''; } function inputCheckbox($name,$value,$extras='') { return 'get($name)) && array_search($value,$this->get($name)) !== false ? ' checked' : '').'/>'; } function inputTextArea($name,$extras='') { return ''; } function inputSelect($name,$values,$extras='') { $return = ''; return $return; } function inputPassword($name,$extras='') { return ''; } function inputHidden($name,$value='') { return ''; } function formTag($name,$action='',$method='post',$other='') { return '