3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.0 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Stig Bakken <ssb@fast.no> |
17 // | Urs Gehrig <urs@circle.ch> |
18 // +----------------------------------------------------------------------+
20 // $Id: form.inc,v 1.1.1.1 2003/04/18 11:10:05 kybu Exp $
22 // HTML form utility functions.
25 if (!defined('HTML_FORM_TEXT_SIZE')) {
26 define('HTML_FORM_TEXT_SIZE', 20);
32 /** ACTION attribute of <FORM> tag */
35 /** METHOD attribute of <FORM> tag */
38 /** NAME attribute of <FORM> tag */
41 /** an array of entries for this form */
44 /** DB_storage object, if tied to one */
47 /** Encryption type */
53 function HTML_Form($action, $method = 'GET', $name = '', $enctype = '',$onsubmit=false) {
54 $this->enctype = $enctype;
55 $this->action = $action;
56 $this->method = $method;
58 $this->fields = array();
59 $this->onSubmit = $onsubmit;
66 function addText($name, $title, $default, $size = HTML_FORM_TEXT_SIZE) {
67 $this->fields[] = array("text", $name, $title, $default, $size);
73 function addFile($name,$title,$accept="image/*,text/plain") {
74 $this->fields[]= array("file",$name,$title,$accept);
77 function addPassword($name, $title, $default, $size = HTML_FORM_PASSWD_SIZE) {
78 $this->fields[] = array("password", $name, $title, $default, $size);
84 function addCheckbox($name, $title, $default) {
85 $this->fields[] = array("checkbox", $name, $title, $default);
91 function addTextarea($name, $title, $default,
92 $width = HTML_FORM_TEXTAREA_WT,
93 $height = HTML_FORM_TEXTAREA_HT) {
94 $this->fields[] = array("textarea", $name, $title, &$default, $width, $height);
100 function addSubmit($name = "submit", $title = "Submit Changes") {
101 $this->fields[] = array("submit", $name, $title);
107 function addReset($title = "Discard Changes") {
108 $this->fields[] = array("reset", $title);
114 function addSelect($name, $title, $entries, $default = '', $size = 1,
115 $blank = '', $multiple = false) {
116 $this->fields[] = array("select", $name, $title, &$entries, $default, $size,
123 function addRadio($name, $title, $value, $default) {
124 $this->fields[] = array("radio", $name, $title, $value, $default);
130 function addImage($name, $src) {
131 $this->fields[] = array("image", $name, $src);
137 function addHidden($name, $value) {
138 $this->fields[] = array("hidden", $name, $value);
146 print "<FORM ACTION=\"" . basename ($this->action) . "\" METHOD=\"$this->method\"";
148 print " NAME=\"$this->name\"";
150 if ($this->enctype) {
151 print " ENCTYPE=\"$this->enctype\"";
154 if($this->onSubmit) {
155 print " onSubmit=\"return validate(this)\"";
165 reset($this->fields);
166 while (list($i, $data) = each($this->fields)) {
167 if ($data[0] == 'reset') {
170 $fields[$data[1]] = true;
172 $this->displayHidden("_fields", implode(":", array_keys($fields)));
179 function displayFile($name, $accept) {
180 print "<INPUT type=file NAME=\"$name\" accept=\"$accept\">";
183 function displayFileRow($name, $title, $accept) {
185 print " <TH ALIGN=\"right\">$title</TH>";
187 $this->displayFile($name, $accept);
192 function displayText($name, $default = '', $size = HTML_FORM_TEXT_SIZE) {
193 print "<INPUT NAME=\"$name\" VALUE=\"$default\" SIZE=\"$size\">";
197 // {{{ displayTextRow()
199 function displayTextRow($name, $title, $default = '', $size = HTML_FORM_TEXT_SIZE) {
201 print " <TH ALIGN=\"right\">$title</TH>";
203 $this->displayText($name, $default, $size);
209 // {{{ displayPassword()
211 function displayPassword($name, $default = '', $size = HTML_FORM_PASSWD_SIZE) {
212 print "<INPUT NAME=\"$name\" TYPE=\"password\" VALUE=\"$default\" SIZE=\"$size\">";
216 // {{{ displayPasswordRow()
218 function displayPasswordRow($name, $title, $default = '', $size = HTML_FORM_PASSWD_SIZE) {
220 print " <TH ALIGN=\"right\">$title</TH>\n";
222 $this->displayPassword($name, $default, $size);
224 $this->displayPassword($name."2", $default, $size);
230 // {{{ displayCheckbox()
232 function displayCheckbox($name, $default = false) {
233 print "<INPUT TYPE=\"checkbox\" NAME=\"$name\"";
234 if ($default && $default != 'off') {
241 // {{{ displayCheckboxRow()
243 function displayCheckboxRow($name, $title, $default = false) {
245 print " <TH ALIGN=\"left\">$title</TH>";
247 $this->displayCheckbox($name, $default);
253 // {{{ displayTextarea()
255 function displayTextarea($name, $default = '', $width = 40, $height = 5) {
256 print "<TEXTAREA NAME=\"$name\" COLS=\"$width\" ROWS=\"$height\">";
262 // {{{ displayTextareaRow()
264 function displayTextareaRow($name, $title, $default = '', $width = 40, $height = 5) {
266 print " <TH ALIGN=\"right\">$title</TH>\n";
268 $this->displayTextarea($name, &$default, $width, $height);
274 // {{{ displaySubmit()
276 function displaySubmit($title = 'Submit Changes', $name = "submit") {
277 print $this->displaySubmit($title, $name);
281 // {{{ displaySubmitRow()
283 function displaySubmitRow($name = "submit", $title = 'Submit Changes') {
284 print $this->returnSubmitRow($name, $title);
288 // {{{ displayReset()
290 function displayReset($title = 'Clear contents') {
291 print $this->returnReset($title);
295 // {{{ displayResetRow()
297 function displayReset($title = 'Clear contents') {
298 print $this->returnReset($title);
302 // {{{ displaySelect()
304 function displaySelect($name, $entries, $default = '', $size = 1,
305 $blank = '', $multiple = false) {
306 print $this->returnSelect($name, $entries, $default, $size, $blank,
311 // {{{ displaySelectRow()
313 function displaySelectRow($name, $title, &$entries, $default = '',
314 $size = 1, $blank = '', $multiple = false)
316 print $this->returnSelectRow($name, $title, $entries, $default, $size,
321 // {{{ displayHidden()
323 function displayHidden($name, $value) {
324 print $this->returnHidden($name, $value);
329 // XXX missing: displayRadio displayRadioRow
333 function returnText($name, $default = '', $size = HTML_FORM_TEXT_SIZE) {
334 return "<INPUT NAME=\"$name\" VALUE=\"$default\" SIZE=\"$size\">";
338 // {{{ returnTextRow()
340 function returnTextRow($name, $title, $default = '', $size = HTML_FORM_TEXT_SIZE) {
342 $str .= " <TH ALIGN=\"right\">$title</TH>";
344 $str .= $this->returnText($name, $default, $size);
352 // {{{ returnPassword()
354 function returnPassword($name, $default = '', $size = HTML_FORM_PASSWD_SIZE) {
355 return "<INPUT NAME=\"$name\" TYPE=\"password\" VALUE=\"$default\" SIZE=\"$size\">";
359 // {{{ returnPasswordRow()
361 function returnPasswordRow($name, $title, $default = '', $size = HTML_FORM_PASSWD_SIZE) {
363 $str .= " <TH ALIGN=\"right\">$title</TH>\n";
365 $str .= $this->returnPassword($name, $default, $size);
367 $str .= $this->returnPassword($name."2", $default, $size);
375 // {{{ returnCheckbox()
377 function returnCheckbox($name, $default = false) {
378 $str .= "<INPUT TYPE=\"checkbox\" NAME=\"$name\"";
379 if ($default && $default != 'off') {
388 // {{{ returnCheckboxRow()
390 function returnCheckboxRow($name, $title, $default = false) {
392 $str .= " <TH ALIGN=\"right\">$title</TH>\n";
394 $str .= $this->returnCheckbox($name, $default);
402 // {{{ returnTextarea()
404 function returnTextarea($name, $default = '', $width = 40, $height = 5) {
405 $str .= "<TEXTAREA NAME=\"$name\" COLS=\"$width\" ROWS=\"$height\">";
407 $str .= "</TEXTAREA>";
413 // {{{ returnTextareaRow()
415 function returnTextareaRow($name, $title, $default = '', $width = 40, $height = 5) {
417 $str .= " <TH ALIGN=\"right\">$title</TH>\n";
419 $str .= $this->returnTextarea($name, &$default, $width, $height);
427 // {{{ returnSubmit()
429 function returnSubmit($title = 'Submit Changes', $name = "submit") {
430 return "<INPUT NAME=\"$name\" TYPE=\"submit\" VALUE=\"$title\">";
434 // {{{ returnSubmitRow()
436 function returnSubmitRow($name = "submit", $title = 'Submit Changes') {
438 $str .= " <TD> </TD>\n";
440 $str .= $this->returnSubmit($title, $name);
450 function returnReset($title = 'Clear contents') {
451 return "<INPUT TYPE=\"reset\" VALUE=\"$title\">";
455 // {{{ returnResetRow()
457 function returnResetRow($title = 'Clear contents') {
459 $str .= " <TD> </TD>\n";
461 $str .= $this->returnReset($title);
469 // {{{ returnSelect()
471 function returnSelect($name, $entries, $default = '', $size = 1,
472 $blank = '', $multiple = false) {
473 $str .= " <SELECT NAME=\"$name\"";
475 $str .= " SIZE=\"$size\"";
482 $str .= " <OPTION VALUE=\"\">$blank\n";
484 while (list($val, $text) = each($entries)) {
486 if ($default && $default == $val) {
489 $str .= "VALUE=\"$val\">$text\n";
491 $str .= " </SELECT>\n";
497 // {{{ returnSelectRow()
499 function returnSelectRow($name, $title, &$entries, $default = '', $size = 1,
500 $blank = '', $multiple = false)
503 $str .= " <TH ALIGN=\"right\">$title:</TH>\n";
505 $str .= $this->returnSelect($name, &$entries, $default, $size, $blank, $multiple);
513 // {{{ returnHidden()
515 function returnHidden($name, $value) {
516 return "<INPUT TYPE=\"hidden\" NAME=\"$name\" VALUE=\"$value\">";
523 function returnStart() {
524 $ret = "<FORM ACTION=\"" . basename ($this->action) . "\" METHOD=\"$this->method\"";
526 $ret .= " NAME=\"$this->name\"";
535 function returnEnd() {
537 reset($this->fields);
538 while (list($i, $data) = each($this->fields)) {
539 if ($data[0] == 'reset') {
542 $fields[$data[1]] = true;
544 $ret = $this->returnHidden("_fields", implode(":", array_keys($fields)));
556 reset($this->fields);
558 $call_cache = array();
559 while (list($i, $data) = each($this->fields)) {
589 // unknown field type
592 $str = $call_cache[$params];
594 $str = '$this->display'.ucfirst($data[0])."Row(";
595 for ($i = 1; $i <= $params; $i++) {
596 $str .= '$data['.$i.']';
597 if ($i < $params) $str .= ', ';
600 $call_cache[$params] = $str;
605 for ($i = 0; $i < sizeof($hidden); $i++) {
606 $this->displayHidden($this->fields[$hidden[$i]][1],
607 $this->fields[$hidden[$i]][2]);
617 function showForm($login='',$email='',$web='',$info='',$skinarray) {;
618 $this->addText("login","Prihlasovacie meno:",$login);
619 $this->addPassword("password1","Heslo:","",10);
620 $this->addPassword("password2","Heslo pre overenie:","",10);
621 $this->addText("email:","Emailova adresa",$email);
622 $this->addText("web","Stranka:",$web);
623 $this->addSelect("skin","Skin:",$skinarray);
624 $this->addFile("image","Obrazok:");
625 $this->addTextarea("info","Dodatocne informacie",$info);
626 $this->addSubmit("submit","Zaregistruj sa!","");
627 $this->addHidden("sent","ok");