📄 form_functions.php
字号:
<?php
// +-------------------------------------------------------------+
// | DeskPRO v [2.0.1 Production]
// | Copyright (C) 2001 - 2004 Headstart Solutions Limited
// | Supplied by WTN-WDYL
// | Nullified by WTN-WDYL
// | Distribution via WebForum, ForumRU and associated file dumps
// +-------------------------------------------------------------+
// | DESKPRO IS NOT FREE SOFTWARE
// +-------------------------------------------------------------+
// | License ID : Full Enterprise License =) ...
// | License Owner : WTN-WDYL Team
// +-------------------------------------------------------------+
// | $RCSfile: form_functions.php,v $
// | $Date: 2004/02/10 01:34:25 $
// | $Revision: 1.40 $
// +-------------------------------------------------------------+
// | File Details:
// | - Utility functions for HTML form widget generation.
// +-------------------------------------------------------------+
error_reporting(E_ALL ^ E_NOTICE);
#################################################################################################
# FORM_x FUNCTIONS
#################################################################################################
/*****************************************************
function html_image
-----DESCRIPTION: -----------------------------------
creates an image
-----ARGUMENTS: -------------------------------------
filename Name of the image on-disk
alt Alternate text to display for the image
width Width of the image
height Height of the image
javascript JavaScript to include in the <IMG> tag
-----RETURNS:----------------------------------------
the html for the form field
*****************************************************/
function html_image($name, $alt='', $width='', $height='', $js='') {
if (!$width or $height) {
$size = @getimagesize(LOC_IMAGES . $name);
if (!$width OR $width == 0) {
$width = $size[0];
}
if (!$height OR $height == 0) {
$height = $size[1];
}
}
$html = "<img src=\"" . constant('LOC_IMAGES') . $name . "\"";
if ($alt) {
$html .= " alt=\"$alt\" title=\"$alt\"";
}
if ($width) {
$html .= " width=\"$width\"";
}
if ($height) {
$html .= " height=\"$height\"";
}
if ($js) {
$html .= " $js";
}
$html .= " border=\"0\" />";
return $html;
}
/*****************************************************
function form_file
-----DESCRIPTION: -----------------------------------
creates a file form element
-----ARGUMENTS: -------------------------------------
name : makes the name of the file
attachment.name (ie the name always
starts with attachment)
-----RETURNS:----------------------------------------
the html for the form field
*****************************************************/
function form_file($name = '') {
$name = 'attachment' . $name;
return "<input type=\"file\" name=\"$name\" />";
}
/*****************************************************
function form_input
-----DESCRIPTION: -----------------------------------
creates a file form element
htmlspecialchars_uni of the value
-----ARGUMENTS: -------------------------------------
name : the name of the textfield
value : the default value for the textfield
size (DEF=30) : the length of the textfield
array : if the textfield is part of an array, ie array[fieldname]
override : if we do not want to htmlspecialchars_uni() the value
js : any extra code in the <input> (for example js)
-----RETURNS:----------------------------------------
the html for the form field
*****************************************************/
function form_input($name, $value=NULL, $size="30", $array='', $override = NULL, $extra='') {
if ($value != NULL) {
if (!$override) {
$value = htmlspecialchars_uni($value);
}
}
if ($array) {
$name = $array . "[" . $name . "]";
}
return "<input type=\"text\" name=\"$name\" value=\"$value\" size=\"$size\" $extra \>";
}
/*****************************************************
function form_password
-----DESCRIPTION: -----------------------------------
creates a file form element
htmlspecialchars_uni of the value
questionable use of value, not really secure
-----ARGUMENTS: -------------------------------------
name : the name of the password field
value : the default value for the password field
size (DEF=30) : the length of the password field
array : if the textfield is part of an array, ie array[fieldname]
-----RETURNS:----------------------------------------
the html for the password field
*****************************************************/
function form_password($name, $value="", $size="30", $array='', $override = NULL) {
if ($value) {
if (!$override) {
$value = htmlspecialchars_uni($value);
}
}
if ($array) {
$name = $array . "[" . $name . "]";
}
return "<input type=\"password\" name=\"$name\" value=\"$value\" size=\"$size\">";
}
/*****************************************************
function form_select
-----DESCRIPTION: -----------------------------------
- creates a drop down list
-----ARGUMENTS: -------------------------------------
name : the name of the select field
array : the array of data for the select field. Can be associative or not
to_array : if the select field is part of an array, ie array[fieldname]
start : the default selected value
same : makes the value the same as the displayed value, otherwise it would use either the specified
values if an associatve array or would use incrementing numbers if standard array
extra : * needs to be looked into, -1 is probably a better value here * creates a "None Selected" row with the value -----
size : if specified makes the select a multiselect form element and determines the size (vertically)
top : add some custom code in the <select > element. Generally used for javascript actions
override : override htmlspecialchars() call
id : Element ID tag value
disabled : Show the element as a disabled one
-----RETURNS:----------------------------------------
the html for the select field
*****************************************************/
function form_select($name, $array, $to_array='', $start='', $same='0', $extra='', $size='', $top='', $override = NULL, $id = NULL, $disabled = NULL) {
if ($to_array != "") {
$name = $to_array . "[" . $name . "]";
}
if ($size) {
$name = $name . "[]";
}
if ($id) {
$id = " id=\"$id\"";
}
if ($disabled) {
$disabled = " DISABLED=disabled ";
$name = $name."_disable";
}
if ($size) {
$html .= "<select name=\"$name\" size=\"$size\" $disabled $top MULTIPLE $id>\n";
} else {
$html .= "<select name=\"$name\" $disabled $id $top>\n";
}
if ($extra) {
$html .= "<option value=\"-----\">None Selected</option>\n";
}
if (is_array($array)) {
while (list ($key, $val) = each ($array)) {
if ($same) {
$key = $val;
}
if (!$override) {
$key = htmlspecialchars_uni($key);
$val = htmlspecialchars_uni($val);
}
if (is_array($start)) {
if (in_array($key, $start)) {
$html .= "<option selected=selected value=\"$key\">$val</option>\n";
} else {
$html .= "<option value=\"$key\">$val</option>\n";
}
} else {
if ($key == $start) {
$html .= "<option selected=selected value=\"$key\">$val</option>\n";
} else {
$html .= "<option value=\"$key\">$val</option>\n";
}
}
}
}
$html .= "</select>\n";
return $html;
}
/*****************************************************
function form_radio
-----DESCRIPTION: -----------------------------------
- creates radio buttons
-----ARGUMENTS: -------------------------------------
name : array of names
value : array of values
start : the value that is preselected
array : if the radio elements are part of an array, ie array[fieldname]
extra : extra code to go in the <input > fields. Used for js actions
-----RETURNS:----------------------------------------
the html for the radio fields
*****************************************************/
function form_radio($name, $value, $start='', $array='', $extra='', $override = NULL) {
if ($array) {
$name = $array . "[" . $name . "]";
}
$num_elements = count($value);
$form = "<table>";
for ($idx = 0; $idx < $num_elements; ++$idx) {
$form .= "<tr><td>$r[normalfont]$value[$idx]:</font></td><td>";
if (!$override) {
$value[$idx] = htmlspecialchars_uni($value[$idx]);
}
if ($value[$idx] == $start) {
$form .= "<input type=\"radio\" name=\"$name\" value=\"$value[$idx]\" checked $extra></td></tr>\n";
} else {
$form .= "<input type=\"radio\" name=\"$name\" value=\"$value[$idx]\" $extra></td></tr>\n";
}
}
$form .= "</table>";
return $form;
}
/*****************************************************
function form_radio_single
-----DESCRIPTION: -----------------------------------
- creates a single radio button
-----ARGUMENTS: -------------------------------------
name : name
value : value
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -