⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form_functions.php

📁 jsp程序开发系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	start			: the value that is preselected
	extra			: extra code to go in the <input > fields. Used for js actions

-----RETURNS:----------------------------------------
	the html for the radio field

*****************************************************/

function form_radio_single($name, $value, $start='', $extra='', $override = NULL) {
	if ($value) {
		if (!$override) {
			$value = htmlspecialchars_uni($value);
		}
	}
	if ($start) {
		return "<input type=\"radio\" name=\"$name\" value=\"$value\" checked $extra />";
	} else {
		return "<input type=\"radio\" name=\"$name\" value=\"$value\"$extra />";
	}
}

/*****************************************************
	function form_radio_yn

-----DESCRIPTION: -----------------------------------
	- creates a yes/no radio button set
	- these can be replaced with a checkbox, but are often more explanative.

-----ARGUMENTS: -------------------------------------
	name			: name
	array			: value
	yes				: the value that is preselected
	empty			: add a 3rd "empty" option, ie neither Yes or No
	extra			: extra code to go in the <input > fields. Used for js actions

-----RETURNS:----------------------------------------
	the html for the radio fields

*****************************************************/

function form_radio_yn($name, $array='', $yes='0', $empty='0', $extra='') {
	if ($array) {
		$name = $array . "[" . $name . "]";
	}
	if ($empty) {
		if ($yes == "1") {
			$html .= "<b>";
			$html .= "Either: <input type=\"radio\" name=\"$name\" value=\"xxxNULLxxx\" $extra>\n";
			$html .= "Yes: <input type=\"radio\" name=\"$name\" value=\"1\" checked  $extra>\n";
			$html .= "No: <input type=\"radio\" name=\"$name\" value=\"0\"  $extra>\n";
			$html .= "</b>";
		} elseif ($yes == "0") {
			$html .= "<b>";
			$html .= "Either: <input type=\"radio\" name=\"$name\" value=\"xxxNULLxxx\" $extra>\n";
			$html .= "Yes: <input type=\"radio\" name=\"$name\" value=\"1\" $extra>\n";
			$html .= "No: <input type=\"radio\" name=\"$name\" value=\"0\" checked $extra>\n";
			$html .= "</b>";
		} else {
			$html .= "<b>";
			$html .= "Either: <input type=\"radio\" name=\"$name\" value=\"xxxNULLxxx\" checked $extra>\n";
			$html .= "Yes: <input type=\"radio\" name=\"$name\" value=\"1\" $extra>\n";
			$html .= "No: <input type=\"radio\" name=\"$name\" value=\"0\" $extra>\n";
			$html .= "</b>";
		}
	} else {
		if ($yes) {
			$html .= "<b>";
			$html .= "Yes: <input type=\"radio\" name=\"$name\" value=\"1\" checked $extra>\n";
			$html .= "No: <input type=\"radio\" name=\"$name\" value=\"0\" $extra>\n";
			$html .= "</b>";
		} else {
			$html .= "<b>";
			$html .= "Yes: <input type=\"radio\" name=\"$name\" value=\"1\" $extra>\n";
			$html .= "No: <input type=\"radio\" name=\"$name\" value=\"0\" checked $extra>\n";
			$html .= "</b>";
		}
	}
	return $html;
}

###################### function form_checkbox() #######################

function form_checkbox($name, $array, $array2, $override = NULL) {
	$name = $name . "[]";
	$num_elements = count($array);
	for ($idx = 0; $idx < $num_elements; ++$idx) {
		if (!$override) {
			$array[$idx] = htmlspecialchars_uni($array[$idx]);
		}
		$form .= "<br /><input type=\"checkbox\" name=\"$name\" value=\"$array[$idx]\" checked>$array2[$idx]";
	}
	return $form;
}

###################### function form_submit() #######################

function form_submit($value, $name='submit', $override = NULL, $image = NULL) {
	if (!$override) {
		$value = htmlspecialchars_uni($value);
	}
	if ($image) {
		$image = " src=\"$image\"";
		$type = "image";
	} else {
		$type = "submit";
	}
	return "<input type=\"$type\" name=\"$name\" value=\"$value\"$image>";
}

###################### function form_checkbox_single() #######################

function form_checkbox_single($name, $value, $checked=NULL, $arrayto='', $override = NULL) {
	if (!$override) {
		$value = htmlspecialchars_uni($value);
	}
	if ($arrayto) {
		$name = $arrayto . "[" . $name . "]";
	}
	if ($checked) {
		$form .= "<input type=\"checkbox\" name=\"$name\" value=\"$value\" checked>";
	} else {
		$form .= "<input type=\"checkbox\" name=\"$name\" value=\"$value\">";
	}
	return $form;
}

###################### function form_date() #######################

/*
	$name : name of the form generated
	$array : if the form should be submitted as part of an array
	$start : prefill with a unix timestamp
	$make_start : prefill with current date
	$empty : add blank options for an unset date
	$yyyymmdd : prefill with a yyyymmdd date
	$return : array of d/m/y only return those found

*/

function form_date($name, $array='', $start='', $make_start='', $empty='', $yyyymmdd='', $return = array('y', 'm', 'd')) {
	if ($start) {
		$yyyymmdd = date('Y-m-d', $start);
	}
	if ($yyyymmdd) {
		$temp_date = explode('-', $yyyymmdd);
		$start = array();
		$start[day] = $temp_date[2];
		$start[month] = $temp_date[1];
		$start[year] = $temp_date[0];
	} elseif ($make_start == "1") {
		$temp_date = getdate(mktime());
		$start = array();
		$start[day] = $temp_date[mday];
		$start[month] = $temp_date[mon];
		$start[year] = $temp_date[year];
	}

	$day = make_numberarray(1, 31);
	$month = array('1' => 'Jan', '2' => 'Feb', '3' => 'Mar', '4' => 'Apr', '5' => 'May', '6' => 'Jun', '7' => 'Jul', '8' => 'Aug', '9' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
	$year = array('2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020');

	if ($empty) {
		array_unshift_keys($day, '0', '');
		array_unshift_keys($month, '0', '');
		array_unshift_keys($year, '0', '');
	}
	if (in_array('d', $return)) {
		$name_bit = "d" . $name;
		$html = form_select($name_bit, $day, $array, $start[day], '1');
	}
	if (in_array('m', $return)) {
		$name_bit = "m" . $name;
		$html .= form_select($name_bit, $month, $array, $start[month], '');
	}
	if (in_array('y', $return)) {
		$name_bit = "y" . $name;
		$html .= form_select($name_bit, $year, $array, $start[year], '1');
	}
	
	return $html;
}

/*****************************************************
	function form_date_year

-----DESCRIPTION-------------------------------------
	Emit a drop-down form widget containing years
	ranged from 2000 to 2020, optionally with a
	specific year already selected.

-----ARGUMENTS---------------------------------------
	name	: Element name (in-HTML)
	year	: Year to pre-select (default is 2003)

-----RETURNS:----------------------------------------
	The HTML to generate the widget

*****************************************************/


function form_date_year($name, $sel_year = '2003') {
	$year = array('2000', '2001', '2002', '2003', '2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020');
	$html = form_select($name, $year, NULL, $sel_year, 1);
	return $html;
}

###################### function form_time() #######################
function form_time($name, $make_start=NULL, $twelve='') {
	if ($make_start) {
		$make_start = split(':', $make_start);
		$start_hours = $make_start[0];
		$start_mins = $make_start[1];
		$start_secs = $make_start[2];
	}
	if ($twelve) {
		$hours = make_numberarray(1, 12);
		if ($start_hours > 12) {
			$start_hours -= 12;
		}
	} else {
		$hours = make_numberarray(0, 23);
	}

	$minutes = make_numberarray(0, 59);
	$name_bit = "h" . $name;
	$html = form_select($name_bit, $hours, $array, $start_hours, '1');
	
	$html .= " : ";
	$name_bit = "m" . $name;
	$html .= form_select($name_bit, $minutes, $array, $start_mins, '');

	if ($twelve) {
		$name_bit = "twelve" . $name;
		$html .= form_select($name_bit, array('AM' => 'AM', 'PM' => 'PM'));
	}

	return $html;
}

###################### function form_textarea() #######################
/*	- create a text area
- the $to_array is used if we want post data to be sent as part of an array
*/

function form_textarea($name, $cols='30', $rows='5', $value='', $to_array='', $override = NULL, $extra='') {
	if (!$override) {
		$value = htmlspecialchars_uni($value);
	}
	if ($cols == "") $cols = 30;
	if ($rows == "") $rows = 5;
	if ($to_array != "") {
		$name = $to_array . "[" . $name . "]";
	}
	$temp = "<textarea name=\"$name\" cols=\"$cols\" rows=\"$rows\" $extra>$value</textarea>\n";
	return $temp;
}

###################### function form_hidden() #######################

function form_hidden($name, $value, $arrayto='', $override = NULL) {
	if ($arrayto) {
		$name = $arrayto . "[" . $name . "]";
	}
	if (!$override) {
		if (is_string($value)) {
			$value = htmlspecialchars_uni($value);
		}
	}
	return "<input type=\"hidden\" name=\"$name\" value=\"$value\">\n";
}

###################### function form_button() #######################

function form_button($value, $js) {
	return "<input type=\"button\" name=\"$value\" value=\"$value\" $js \>";
}

################### function htmlspecialchars_uni($data) ##################

// This function can be safely run on strings that have already been
// passed through htmlspecialchars_uni(); it leaves existing "&amp;" style
// entities alone.

function htmlentities2($data) {
	$translation_table = get_html_translation_table (HTML_ENTITIES,ENT_QUOTES);
	$translation_table[chr(38)] = '&';
	return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&amp;" , strtr($data, $translation_table));
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -