2006-12-02 04:36:16 +00:00
|
|
|
<?php
|
|
|
|
/*
|
2008-12-12 16:36:45 +00:00
|
|
|
* e107 website system
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001-2008 e107 Inc (e107.org)
|
|
|
|
* Released under the terms and conditions of the
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
|
|
|
*
|
|
|
|
* Form Handler
|
|
|
|
*
|
|
|
|
* $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $
|
2008-12-19 14:01:07 +00:00
|
|
|
* $Revision: 1.11 $
|
|
|
|
* $Date: 2008-12-19 14:01:07 $
|
2008-12-12 16:36:45 +00:00
|
|
|
* $Author: secretr $
|
|
|
|
*
|
2006-12-02 04:36:16 +00:00
|
|
|
*/
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
if (!defined('e107_INIT')) { exit; }
|
|
|
|
|
2008-12-12 16:36:45 +00:00
|
|
|
/**
|
|
|
|
* Automate Form fields creation. Produced markup is following e107 CSS/XHTML standards
|
|
|
|
* If options argument is omitted, default values will be used (which OK most of the time)
|
|
|
|
* Options are intended to handle some very special cases.
|
|
|
|
*
|
|
|
|
* Overall field options format (array or GET string like this one: var1=val1&var2=val2...):
|
|
|
|
*
|
|
|
|
* - id => (mixed) custom id attribute value
|
|
|
|
* if numeric value is passed it'll be just appended to the name e.g. {filed-name}-{value}
|
|
|
|
* if false is passed id will be not created
|
|
|
|
* if empty string is passed (or no 'id' option is found)
|
|
|
|
* in all other cases the value will be used as field id
|
|
|
|
* default: empty string
|
|
|
|
*
|
|
|
|
* - class => (string) field class(es)
|
|
|
|
* Example: 'tbox select class1 class2 class3'
|
|
|
|
* NOTE: this will override core classes, so you have to explicit include them!
|
|
|
|
* default: empty string
|
|
|
|
*
|
|
|
|
* - size => (int) size attribute value (used when needed)
|
|
|
|
* default: 40
|
2008-12-16 14:22:01 +00:00
|
|
|
*
|
2008-12-12 22:39:17 +00:00
|
|
|
* - title (string) title attribute
|
|
|
|
* default: empty string (omitted)
|
2008-12-12 16:36:45 +00:00
|
|
|
*
|
|
|
|
* - readonly => (bool) readonly attribute
|
|
|
|
* default: false
|
2008-12-16 14:22:01 +00:00
|
|
|
*
|
2008-12-12 22:39:17 +00:00
|
|
|
* - selected => (bool) selected attribute (used when needed)
|
|
|
|
* default: false
|
2008-12-16 14:22:01 +00:00
|
|
|
*
|
2008-12-12 22:39:17 +00:00
|
|
|
* checked => (bool) checked attribute (used when needed)
|
|
|
|
* default: false
|
2008-12-12 16:36:45 +00:00
|
|
|
* - disabled => (bool) disabled attribute
|
|
|
|
* default: false
|
|
|
|
*
|
|
|
|
* - tabindex => (int) tabindex attribute value
|
|
|
|
* default: inner tabindex counter
|
|
|
|
*
|
|
|
|
* - other => (string) additional data
|
|
|
|
* Example: 'attribute1="value1" attribute2="value2"'
|
|
|
|
* default: empty string
|
|
|
|
*/
|
|
|
|
class e_form
|
|
|
|
{
|
|
|
|
var $_tabindex_counter = 0;
|
|
|
|
var $_tabindex_enabled = true;
|
|
|
|
var $_cached_attributes = array();
|
|
|
|
|
2008-12-17 11:08:31 +00:00
|
|
|
function e_form($enable_tabindex = false)
|
2008-12-12 16:36:45 +00:00
|
|
|
{
|
|
|
|
$this->_tabindex_enabled = $enable_tabindex;
|
|
|
|
}
|
|
|
|
|
|
|
|
function text($name, $value, $maxlength = 200, $options = array())
|
|
|
|
{
|
|
|
|
$options = $this->format_options('text', $name, $options);
|
2008-12-17 11:08:31 +00:00
|
|
|
//never allow id in format name-value for text fields
|
|
|
|
return "<input type='text' name='{$name}' value='{$value}' maxlength='{$maxlength}'".$this->get_attributes($options, $name)." />";
|
2008-12-12 16:36:45 +00:00
|
|
|
}
|
|
|
|
|
2008-12-16 14:22:01 +00:00
|
|
|
function file($name, $options = array())
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
$options = $this->format_options('text', $name, $options);
|
2008-12-17 11:08:31 +00:00
|
|
|
//never allow id in format name-value for text fields
|
|
|
|
return "<input type='text' name='{$name}'".$this->get_attributes($options, $name)." />";
|
2008-12-12 22:39:17 +00:00
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
2008-12-12 22:39:17 +00:00
|
|
|
|
2008-12-12 16:36:45 +00:00
|
|
|
function password($name, $maxlength = 50, $options = array())
|
|
|
|
{
|
|
|
|
$options = $this->format_options('text', $name, $options);
|
2008-12-17 11:08:31 +00:00
|
|
|
//never allow id in format name-value for text fields
|
|
|
|
return "<input type='password' name='{$name}' value='' maxlength='{$maxlength}'".$this->get_attributes($options, $name)." />";
|
2008-12-12 16:36:45 +00:00
|
|
|
}
|
|
|
|
|
2008-12-12 22:39:17 +00:00
|
|
|
function textarea($name, $value, $rows = 15, $cols = 40, $options = array())
|
2008-12-12 16:36:45 +00:00
|
|
|
{
|
2008-12-12 22:39:17 +00:00
|
|
|
$options = $this->format_options('textarea', $name, $options);
|
2008-12-17 11:08:31 +00:00
|
|
|
//never allow id in format name-value for text fields
|
|
|
|
return "<textarea name='{$name}' rows='{$rows}' cols='{$cols}'".$this->get_attributes($options, $name).">{$value}</textarea>";
|
2008-12-12 22:39:17 +00:00
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
|
|
|
function checkbox($name, $value, $checked = false, $options = array())
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
$options['checked'] = $checked; //comes as separate argument just for convenience
|
|
|
|
$options = $this->format_options('checkbox', $name, $options);
|
2008-12-12 23:29:32 +00:00
|
|
|
return "<input type='checkbox' name='{$name}' value='{$value}'".$this->get_attributes($options, $name, $value)." />";
|
2008-12-12 22:39:17 +00:00
|
|
|
|
2008-12-12 16:36:45 +00:00
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
|
|
|
function radio($name, $value, $checked = false, $options = array())
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
$options['checked'] = $checked; //comes as separate argument just for convenience
|
|
|
|
$options = $this->format_options('radio', $name, $options);
|
2008-12-12 23:29:32 +00:00
|
|
|
return "<input type='radio' name='{$name}' value='".$value."'".$this->get_attributes($options, $name, $value)." />";
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2008-12-12 22:39:17 +00:00
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
2008-12-19 14:01:07 +00:00
|
|
|
function radio_switch($name, $checked_enabled = false, $label_enabled = '', $label_disabled = '')
|
|
|
|
{
|
|
|
|
return $this->radio($name, 1, $checked_enabled)."".$this->label($label_enabled ? $label_enabled : LAN_ENABLED, $name, 1)."
|
|
|
|
".$this->radio($name, 0, !$checked_enabled)."".$this->label($label_disabled ? $label_disabled : LAN_DISABLED, $name, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function radio_multi($name, $elements, $checked)
|
|
|
|
{
|
|
|
|
$text = array();
|
|
|
|
if(is_string($elements)) parse_str($elements, $elements);
|
|
|
|
|
|
|
|
foreach ($elements as $value => $label)
|
|
|
|
{
|
|
|
|
$text[] = $this->radio($name, $value, $checked == $value)."".$this->label($label, $name, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode(" \n", $text);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-16 14:22:01 +00:00
|
|
|
function label($text, $name = '', $value = '')
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
2008-12-12 23:29:32 +00:00
|
|
|
$for_id = $this->_format_id('', $name, $value, 'for');
|
|
|
|
return "<label$for_id>{$text}</label>";
|
2008-12-12 22:39:17 +00:00
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2008-12-16 14:22:01 +00:00
|
|
|
function select_open($name, $options = array())
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
$options = $this->format_options('select', $name, $options);
|
2008-12-12 23:29:32 +00:00
|
|
|
return "<select name='{$name}'".$this->get_attributes($options, $name).">";
|
2008-12-12 22:39:17 +00:00
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
|
|
|
function optgroup_open($label, $disabled)
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
return "<optgroup class='optgroup' label='{$label}'".($disabled ? " disabled='disabled'" : '').">";
|
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
|
|
|
function option($option_name, $value, $selected = false, $options = array())
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
if(false === $value) $value = '';
|
|
|
|
$options['selected'] = $selected; //comes as separate argument just for convenience
|
|
|
|
$options = $this->format_options('option', '', $options);
|
|
|
|
return "<option value='{$value}'".$this->get_attributes($options).">{$option_name}</option>";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2008-12-16 14:22:01 +00:00
|
|
|
function optgroup_close()
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
return "</optgroup>";
|
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
|
|
|
function select_close()
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
return "</select>";
|
|
|
|
}
|
|
|
|
|
2008-12-16 14:22:01 +00:00
|
|
|
function hidden($name, $value, $options = array())
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
$options = $this->format_options('hidden', $name, $options);
|
2008-12-12 23:29:32 +00:00
|
|
|
return "<input type='hidden' name='{$name}' value='{$value}'".$this->get_attributes($options, $name, $value)." />";
|
2008-12-12 22:39:17 +00:00
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
|
|
|
function submit($name, $value, $options = array())
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
|
|
|
$options = $this->format_options('submit', $name, $options);
|
2008-12-17 11:08:31 +00:00
|
|
|
return "<input type='submit' name='{$name}' value='{$value}'".$this->get_attributes($options, $name, $value)." />";
|
2008-12-12 22:39:17 +00:00
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
2008-12-17 11:08:31 +00:00
|
|
|
function submit_image($name, $value, $image, $title='', $options = array())
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
2008-12-17 11:08:31 +00:00
|
|
|
$options = $this->format_options('submit_image', $name, $options);
|
|
|
|
switch ($image) {
|
|
|
|
case 'edit':
|
2008-12-17 11:12:44 +00:00
|
|
|
$image = e_IMAGE_ABS.'admin_images/edit_16.png';
|
2008-12-17 11:08:31 +00:00
|
|
|
$options['class'] = 'action edit';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'delete':
|
2008-12-17 11:12:44 +00:00
|
|
|
$image = e_IMAGE_ABS.'admin_images/delete_16.png';
|
2008-12-17 11:08:31 +00:00
|
|
|
$options['class'] = 'action delete';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$options['title'] = $title;//shorthand
|
|
|
|
|
|
|
|
return "<input type='image' src='{$image}' name='{$name}' value='{$value}'".$this->get_attributes($options, $name, $value)." />";
|
2008-12-12 22:39:17 +00:00
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
2008-12-15 21:16:32 +00:00
|
|
|
function admin_button($name, $value, $action = 'submit', $label = '', $options = array())
|
2008-12-12 22:39:17 +00:00
|
|
|
{
|
2008-12-17 11:08:31 +00:00
|
|
|
|
2008-12-12 22:39:17 +00:00
|
|
|
$btype = 'submit';
|
|
|
|
if($action == 'action') $btype = 'button';
|
|
|
|
$options = $this->format_options('admin_button', $name, $options);
|
2008-12-17 11:08:31 +00:00
|
|
|
$options['class'] = $action;//shorthand
|
2008-12-12 22:39:17 +00:00
|
|
|
if(empty($label)) $label = $value;
|
2008-12-16 14:22:01 +00:00
|
|
|
|
2008-12-12 22:39:17 +00:00
|
|
|
return "
|
2008-12-16 14:22:01 +00:00
|
|
|
<button type='{$btype}' name='{$name}' value='{$value}'".$this->get_attributes($options, $name)."><span>{$label}</span></button>
|
2008-12-12 22:39:17 +00:00
|
|
|
";
|
|
|
|
}
|
2008-12-16 14:22:01 +00:00
|
|
|
|
2008-12-17 11:08:31 +00:00
|
|
|
function getNext()
|
|
|
|
{
|
|
|
|
if(!$this->_tabindex_enabled) return 0;
|
|
|
|
$this->_tabindex_counter += 1;
|
|
|
|
return $this->_tabindex_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
function resetTabindex()
|
|
|
|
{
|
|
|
|
$this->_tabindex_counter = 0;
|
|
|
|
}
|
|
|
|
|
2008-12-12 23:29:32 +00:00
|
|
|
function get_attributes($options, $name = '', $value = '')
|
2008-12-12 16:36:45 +00:00
|
|
|
{
|
|
|
|
$ret = '';
|
|
|
|
//
|
|
|
|
foreach ($options as $option => $optval)
|
|
|
|
{
|
|
|
|
switch ($option) {
|
|
|
|
|
|
|
|
case 'id':
|
2008-12-12 23:29:32 +00:00
|
|
|
$ret .= $this->_format_id($optval, $name, $value);
|
2008-12-12 16:36:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'class':
|
|
|
|
if(!empty($optval)) $ret .= " class='{$optval}'";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'size':
|
|
|
|
if($optval) $ret .= " size='{$optval}'";
|
|
|
|
break;
|
2008-12-16 14:22:01 +00:00
|
|
|
|
2008-12-12 22:39:17 +00:00
|
|
|
case 'title':
|
|
|
|
if($optval) $ret .= " title='{$optval}'";
|
|
|
|
break;
|
2008-12-12 16:36:45 +00:00
|
|
|
|
|
|
|
case 'tabindex':
|
2008-12-17 11:08:31 +00:00
|
|
|
if(false === $optval || !$this->_tabindex_enabled) break;
|
|
|
|
$this->_tabindex_counter += 1;
|
2008-12-12 22:39:17 +00:00
|
|
|
$ret .= " tabindex='".($optval ? $optval : $this->_tabindex_counter)."'";
|
2008-12-12 16:36:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'readonly':
|
|
|
|
if($optval) $ret .= " readonly='readonly'";
|
|
|
|
break;
|
|
|
|
|
2008-12-12 22:39:17 +00:00
|
|
|
case 'selected':
|
|
|
|
if($optval) $ret .= " selected='selected'";
|
|
|
|
break;
|
2008-12-16 14:22:01 +00:00
|
|
|
|
2008-12-12 22:39:17 +00:00
|
|
|
case 'checked':
|
|
|
|
if($optval) $ret .= " checked='checked'";
|
|
|
|
break;
|
|
|
|
|
2008-12-12 16:36:45 +00:00
|
|
|
case 'disabled':
|
|
|
|
if($optval) $ret .= " disabled='disabled'";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'other':
|
|
|
|
if($optval) $ret .= " $optval";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
2008-12-12 23:29:32 +00:00
|
|
|
/**
|
|
|
|
* Auto-build field attribute id
|
|
|
|
*
|
|
|
|
* @param string $id_value value for attribute id passed with the option array
|
|
|
|
* @param string $name the name attribute passed to that field
|
|
|
|
* @param unknown_type $value the value attribute passed to that field
|
|
|
|
* @return unknown
|
|
|
|
*/
|
|
|
|
function _format_id($id_value, $name, $value = '', $return_attribute = 'id')
|
2008-12-12 16:36:45 +00:00
|
|
|
{
|
2008-12-12 23:29:32 +00:00
|
|
|
if($id_value === false) return '';
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2008-12-17 11:08:31 +00:00
|
|
|
//format data first
|
|
|
|
$name = rtrim(str_replace(array('[]', '[', ']', '_'), array('-', '-', '', '-'), $name), '-');
|
|
|
|
$value = trim(preg_replace('#[^a-z0-9\-]/i#','-', $value), '-');
|
|
|
|
|
|
|
|
if(!$id_value && is_numeric($value)) $id_value = $value;
|
2008-12-16 14:22:01 +00:00
|
|
|
|
2008-12-12 23:29:32 +00:00
|
|
|
if(empty($id_value) ) return " {$return_attribute}='{$name}".($value ? "-{$value}" : '')."'";// also useful when name is e.g. name='my_name[some_id]'
|
|
|
|
elseif(is_numeric($id_value) && $name) return " {$return_attribute}='{$name}-{$id_value}'";// also useful when name is e.g. name='my_name[]'
|
|
|
|
else return " {$return_attribute}='{$id_value}'";
|
2008-12-12 16:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format options based on the field type,
|
|
|
|
* merge with default
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
* @param string $name form name attribute value
|
|
|
|
* @param array|string $user_options
|
|
|
|
* @return array merged options
|
|
|
|
*/
|
|
|
|
function format_options($type, $name, $user_options)
|
|
|
|
{
|
|
|
|
if(is_string($user_options)) parse_str($user_options, $user_options);
|
|
|
|
|
|
|
|
$def_options = $this->_default_options($type);
|
|
|
|
|
|
|
|
foreach (array_keys($user_options) as $key)
|
|
|
|
{
|
2008-12-17 11:08:31 +00:00
|
|
|
if(!isset($def_options[$key])) unset($user_options[$key]);//remove it?
|
2008-12-12 16:36:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$user_options['name'] = $name; //required for some of the automated tasks
|
|
|
|
return array_merge($def_options, $user_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get default options array based on the filed type
|
|
|
|
*
|
|
|
|
* @param string $type
|
|
|
|
* @return array default options
|
|
|
|
*/
|
|
|
|
function _default_options($type)
|
|
|
|
{
|
|
|
|
if(isset($this->_cached_attributes[$type])) return $this->_cached_attributes[$type];
|
|
|
|
|
|
|
|
$def_options = array(
|
2008-12-12 22:39:17 +00:00
|
|
|
'id' => '',
|
2008-12-12 16:36:45 +00:00
|
|
|
'class' => '',
|
2008-12-12 22:39:17 +00:00
|
|
|
'title' => '',
|
2008-12-12 16:36:45 +00:00
|
|
|
'size' => '',
|
|
|
|
'readonly' => false,
|
2008-12-12 22:39:17 +00:00
|
|
|
'selected' => false,
|
|
|
|
'checked' => false,
|
2008-12-12 16:36:45 +00:00
|
|
|
'disabled' => false,
|
2008-12-12 22:39:17 +00:00
|
|
|
'tabindex' => 0,
|
2008-12-12 16:36:45 +00:00
|
|
|
'other' => ''
|
|
|
|
);
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'hidden':
|
|
|
|
$def_options = array('disabled' => false, 'other' => '');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'text':
|
|
|
|
$def_options['class'] = 'tbox input-text';
|
2008-12-12 22:39:17 +00:00
|
|
|
unset($def_options['selected'], $def_options['checked']);
|
2008-12-12 16:36:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'textarea':
|
|
|
|
$def_options['class'] = 'tbox textarea';
|
2008-12-12 22:39:17 +00:00
|
|
|
unset($def_options['selected'], $def_options['checked'], $def_options['size']);
|
2008-12-12 16:36:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'select':
|
|
|
|
$def_options['class'] = 'tbox select';
|
2008-12-12 22:39:17 +00:00
|
|
|
unset($def_options['checked'], $def_options['checked']);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'option':
|
|
|
|
$def_options = array('class' => '', 'selected' => false, 'other' => '');
|
2008-12-12 16:36:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'radio':
|
|
|
|
$def_options['class'] = 'radio';
|
2008-12-12 22:39:17 +00:00
|
|
|
unset($def_options['size'], $def_options['selected']);
|
2008-12-12 16:36:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'checkbox':
|
|
|
|
$def_options['class'] = 'checkbox';
|
2008-12-12 22:39:17 +00:00
|
|
|
unset($def_options['size'], $def_options['selected']);
|
2008-12-12 16:36:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'submit':
|
|
|
|
$def_options['class'] = 'button';
|
2008-12-12 22:39:17 +00:00
|
|
|
unset($def_options['checked'], $def_options['selected'], $def_options['readonly']);
|
2008-12-12 16:36:45 +00:00
|
|
|
break;
|
|
|
|
|
2008-12-17 11:08:31 +00:00
|
|
|
case 'submit_image':
|
2008-12-17 11:12:44 +00:00
|
|
|
$def_options['class'] = 'action';
|
2008-12-17 11:08:31 +00:00
|
|
|
unset($def_options['checked'], $def_options['selected'], $def_options['readonly']);
|
|
|
|
break;
|
|
|
|
|
2008-12-12 16:36:45 +00:00
|
|
|
case 'admin_button':
|
2008-12-12 22:39:17 +00:00
|
|
|
unset($def_options['checked'], $def_options['selected'], $def_options['readonly']);
|
2008-12-12 16:36:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->_cached_attributes[$type] = $def_options;
|
|
|
|
return $def_options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
class form {
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_open($form_method, $form_action, $form_name = "", $form_target = "", $form_enctype = "", $form_js = "") {
|
|
|
|
$method = ($form_method ? "method='".$form_method."'" : "");
|
|
|
|
$target = ($form_target ? " target='".$form_target."'" : "");
|
|
|
|
$name = ($form_name ? " id='".$form_name."' " : " id='myform'");
|
|
|
|
return "\n<form action='".$form_action."' ".$method.$target.$name.$form_enctype.$form_js.">";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2008-04-04 21:40:50 +00:00
|
|
|
function form_text($form_name, $form_size, $form_value, $form_maxlength = FALSE, $form_class = "tbox", $form_readonly = "", $form_tooltip = "", $form_js = "") {
|
2006-12-02 04:36:16 +00:00
|
|
|
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
2007-03-23 21:46:57 +00:00
|
|
|
$value = (isset($form_value) ? " value='".$form_value."'" : "");
|
2006-12-02 04:36:16 +00:00
|
|
|
$size = ($form_size ? " size='".$form_size."'" : "");
|
|
|
|
$maxlength = ($form_maxlength ? " maxlength='".$form_maxlength."'" : "");
|
|
|
|
$readonly = ($form_readonly ? " readonly='readonly'" : "");
|
|
|
|
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
|
|
|
return "\n<input class='".$form_class."' type='text' ".$name.$value.$size.$maxlength.$readonly.$tooltip.$form_js." />";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2008-04-04 21:40:50 +00:00
|
|
|
function form_password($form_name, $form_size, $form_value, $form_maxlength = FALSE, $form_class = "tbox", $form_readonly = "", $form_tooltip = "", $form_js = "") {
|
2006-12-02 04:36:16 +00:00
|
|
|
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
2007-03-23 21:46:57 +00:00
|
|
|
$value = (isset($form_value) ? " value='".$form_value."'" : "");
|
2006-12-02 04:36:16 +00:00
|
|
|
$size = ($form_size ? " size='".$form_size."'" : "");
|
|
|
|
$maxlength = ($form_maxlength ? " maxlength='".$form_maxlength."'" : "");
|
|
|
|
$readonly = ($form_readonly ? " readonly='readonly'" : "");
|
|
|
|
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
|
|
|
return "\n<input class='".$form_class."' type='password' ".$name.$value.$size.$maxlength.$readonly.$tooltip.$form_js." />";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_button($form_type, $form_name, $form_value, $form_js = "", $form_image = "", $form_tooltip = "") {
|
|
|
|
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
|
|
|
$image = ($form_image ? " src='".$form_image."' " : "");
|
|
|
|
$tooltip = ($form_tooltip ? " title='".$form_tooltip."' " : "");
|
|
|
|
return "\n<input class='button' type='".$form_type."' ".$form_js." value='".$form_value."'".$name.$image.$tooltip." />";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_textarea($form_name, $form_columns, $form_rows, $form_value, $form_js = "", $form_style = "", $form_wrap = "", $form_readonly = "", $form_tooltip = "") {
|
|
|
|
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
|
|
|
$readonly = ($form_readonly ? " readonly='readonly'" : "");
|
|
|
|
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
|
|
|
$wrap = ($form_wrap ? " wrap='".$form_wrap."'" : "");
|
|
|
|
$style = ($form_style ? " style='".$form_style."'" : "");
|
|
|
|
return "\n<textarea class='tbox' cols='".$form_columns."' rows='".$form_rows."' ".$name.$form_js.$style.$wrap.$readonly.$tooltip.">".$form_value."</textarea>";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_checkbox($form_name, $form_value, $form_checked = 0, $form_tooltip = "", $form_js = "") {
|
|
|
|
$name = ($form_name ? " id='".$form_name.$form_value."' name='".$form_name."'" : "");
|
|
|
|
$checked = ($form_checked ? " checked='checked'" : "");
|
|
|
|
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
|
|
|
return "\n<input type='checkbox' value='".$form_value."'".$name.$checked.$tooltip.$form_js." />";
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_radio($form_name, $form_value, $form_checked = 0, $form_tooltip = "", $form_js = "") {
|
|
|
|
$name = ($form_name ? " id='".$form_name.$form_value."' name='".$form_name."'" : "");
|
|
|
|
$checked = ($form_checked ? " checked='checked'" : "");
|
|
|
|
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
|
|
|
return "\n<input type='radio' value='".$form_value."'".$name.$checked.$tooltip.$form_js." />";
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_file($form_name, $form_size, $form_tooltip = "", $form_js = "") {
|
|
|
|
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
|
|
|
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
|
|
|
return "<input type='file' class='tbox' size='".$form_size."'".$name.$tooltip.$form_js." />";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_select_open($form_name, $form_js = "") {
|
|
|
|
return "\n<select id='".$form_name."' name='".$form_name."' class='tbox' ".$form_js." >";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_select_close() {
|
|
|
|
return "\n</select>";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_option($form_option, $form_selected = "", $form_value = "", $form_js = "") {
|
|
|
|
$value = ($form_value !== FALSE ? " value='".$form_value."'" : "");
|
|
|
|
$selected = ($form_selected ? " selected='selected'" : "");
|
|
|
|
return "\n<option".$value.$selected." ".$form_js.">".$form_option."</option>";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_hidden($form_name, $form_value) {
|
|
|
|
return "\n<input type='hidden' id='".$form_name."' name='".$form_name."' value='".$form_value."' />";
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
function form_close() {
|
|
|
|
return "\n</form>";
|
|
|
|
}
|
|
|
|
}
|
2008-12-12 16:36:45 +00:00
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
/*
|
|
|
|
Usage
|
|
|
|
echo $rs->form_open("post", e_SELF, "_blank");
|
|
|
|
echo $rs->form_text("testname", 100, "this is the value", 100, 0, "tooltip");
|
|
|
|
echo $rs->form_button("submit", "testsubmit", "SUBMIT!", "", "Click to submit");
|
|
|
|
echo $rs->form_button("reset", "testreset", "RESET!", "", "Click to reset");
|
|
|
|
echo $rs->form_textarea("textareaname", 10, 10, "Value", "overflow:hidden");
|
|
|
|
echo $rs->form_checkbox("testcheckbox", 1, 1);
|
|
|
|
echo $rs->form_checkbox("testcheckbox2", 2);
|
|
|
|
echo $rs->form_hidden("hiddenname", "hiddenvalue");
|
|
|
|
echo $rs->form_radio("testcheckbox", 1, 1);
|
|
|
|
echo $rs->form_radio("testcheckbox", 1);
|
|
|
|
echo $rs->form_file("testfile", "20");
|
|
|
|
echo $rs->form_select_open("testselect");
|
|
|
|
echo $rs->form_option("Option 1");
|
|
|
|
echo $rs->form_option("Option 2");
|
|
|
|
echo $rs->form_option("Option 3", 1, "defaultvalue");
|
|
|
|
echo $rs->form_option("Option 4");
|
|
|
|
echo $rs->form_select_close();
|
|
|
|
echo $rs->form_close();
|
|
|
|
*/
|
2008-12-12 16:36:45 +00:00
|
|
|
|
|
|
|
|
2006-12-02 04:36:16 +00:00
|
|
|
?>
|