config->site_url($action).'"';
if ( ! isset($attributes['method']))
{
$form .= ' method="post"';
}
if (is_array($attributes) AND count($attributes) > 0)
{
foreach ($attributes as $key => $val)
{
$form .= ' '.$key.'="'.$val.'"';
}
}
$form .= '>';
if (is_array($hidden) AND count($hidden > 0))
{
$form .= form_hidden($hidden);
}
return $form;
}
// ------------------------------------------------------------------------
/**
* Form Declaration - Multipart type
*
* Creates the opening portion of the form, but with "multipart/form-data".
*
* @access public
* @param string the URI segments of the form destination
* @param array a key/value pair of attributes
* @param array a key/value pair hidden data
* @return string
*/
function form_open_multipart($action, $attributes = array(), $hidden = array())
{
$attributes['enctype'] = 'multipart/form-data';
return form_open($action, $attributes, $hidden);
}
// ------------------------------------------------------------------------
/**
* Hidden Input Field
*
* Generates hidden fields. You can pass a simple key/value string or an associative
* array with multiple values.
*
* @access public
* @param mixed
* @param string
* @return string
*/
function form_hidden($name, $value = '')
{
if ( ! is_array($name))
{
return '';
}
$form = '';
foreach ($name as $name => $value)
{
$form .= '';
}
return $form;
}
// ------------------------------------------------------------------------
/**
* Text Input Field
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
function form_input($data = '', $value = '', $extra = '')
{
$defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50');
return "\n";
}
// ------------------------------------------------------------------------
/**
* Password Field
*
* Identical to the input function but adds the "password" type
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
function form_password($data = '', $value = '', $extra = '')
{
if ( ! is_array($data))
{
$data = array('name' => $data);
}
$data['type'] = 'password';
return form_input($data, $value, $extra);
}
// ------------------------------------------------------------------------
/**
* Upload Field
*
* Identical to the input function but adds the "file" type
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
function form_upload($data = '', $value = '', $extra = '')
{
if ( ! is_array($data))
{
$data = array('name' => $data);
}
$data['type'] = 'file';
return form_input($data, $value, $extra);
}
// ------------------------------------------------------------------------
/**
* Textarea field
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
function form_textarea($data = '', $value = '', $extra = '')
{
$defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12');
$val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']);
return "\n";
}
// ------------------------------------------------------------------------
/**
* Dropdown Menu
*
* @access public
* @param string
* @param array
* @param string
* @param string
* @return string
*/
function form_dropdown($name = '', $options = array(), $selected = '', $extra = '')
{
if ($extra != '') $extra = ' '.$extra;
$form = '';
return $form;
}
// ------------------------------------------------------------------------
/**
* Checkbox Field
*
* @access public
* @param mixed
* @param string
* @param bool
* @param string
* @return string
*/
function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '')
{
$defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
if (isset($data['checked']))
{
$checked = $data['checked'];
if ($checked == FALSE)
unset($data['checked']);
}
if ($checked == TRUE)
$defaults['checked'] = ' checked="checked"';
else
unset($defaults['checked']);
return "\n";
}
// ------------------------------------------------------------------------
/**
* Radio Button
*
* @access public
* @param mixed
* @param string
* @param bool
* @param string
* @return string
*/
function form_radio($data = '', $value = '', $checked = TRUE, $extra = '')
{
if ( ! is_array($data))
{
$data = array('name' => $data);
}
$data['type'] = 'radio';
return form_checkbox($data, $value, $checked, $extra);
}
// ------------------------------------------------------------------------
/**
* Submit Button
*
* @access public
* @param mixed
* @param string
* @param string
* @return string
*/
function form_submit($data = '', $value = '', $extra = '')
{
$defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
return "\n";
}
// ------------------------------------------------------------------------
/**
* Form Close Tag
*
* @access public
* @param string
* @return string
*/
function form_close($extra = '')
{
return "\n".$extra;
}
// ------------------------------------------------------------------------
/**
* Form Prep
*
* Formats text so that it can be safely placed in a form field in the event it has HTML tags.
*
* @access public
* @param string
* @return string
*/
function form_prep($str = '')
{
if ($str === '')
{
return '';
}
return str_replace(array("'", '"'), array("'", """), htmlspecialchars($str));
}
// ------------------------------------------------------------------------
/**
* Parse the form attributes
*
* Helper function used by some of the form helpers
*
* @access private
* @param array
* @parm array
* @return string
*/
function parse_form_attributes($attributes, $default)
{
if (is_array($attributes))
{
foreach ($default as $key => $val)
{
if (isset($attributes[$key]))
{
$default[$key] = $attributes[$key];
unset($attributes[$key]);
}
}
if (count($attributes) > 0)
{
$default = array_merge($default, $attributes);
}
}
$att = '';
foreach ($default as $key => $val)
{
if ($key == 'value')
{
$val = form_prep($val);
}
$att .= $key . '="' . $val . '" ';
}
return $att;
}
?>