phpWebSite developer documentation :
Automated HTML code generation routines
- Background: itemfuncs, form_options() and html_header_location()
- Safe HTML redirection with html_header_location()
- Create menus and radio-boxes with form_options()
- Create clever items tables for Admin panels with itemfuncs
top of page
Background: itemfuncs, form_options() and html_header_location()
Since we started deal with both php 4.1.x and with increasing code complexity we felt in need to create smarter ways to accomplish repetitive tasks without replicating the same code more and more. Functions described in this document had been created to achieve those goals.
Both all three group of functionalities described in this document had been created by Alessandro Pisani.
If you need more info or you have suggestions about them, you can find his email address at the end of this document.
top of page
Safe HTML redirection with html_header_location()
The html_header_location() function is a wrap around the PHP function header() in its most common use: header("Location: url"); (where url is a destination URL). html_header_location() provides compatibility with the different behaviour of the PHP costruct in different browsers (like Microsoft InternetExplorer 5.5 and above, Mozilla 0.9.8 and above, ...) and different versions of PHP.
Return: this function does not return
Function prototype: function html_header_location($url)
Location: htmlheader.php (phpWebSite 0.8.1-CVS feb 2002)
Example: redirect to index.php
top of page
Create menus and radio-boxes with form_options()
form_options() is an automated way to generate HTML input-radio and select-option selections in HTML forms. The function assumes the form is opened and closed respectively before and after it is called.
Function prototype: function form_options($useecho,$type,$name,$options_and_values,$selection)
Return: with $useecho=1 this function does not return, otherwise it returns a string buffer containing resulting HTML code.
- $useecho : if set to 1 form_options() will output generated HTML code using echo() instead of a buffer which is returned to the caller
- $type : it can be set to "radio" (for input-ratio lists) or to "option" (for select-option lists)
- $name : the name of the generated HTML form-control
- $options_and_values : this is an array of couples in the form value,label. Each couple identifies an entry of the list
- $selected : the selected element of the list (it have to be the value of an entry)
Location: mainfile.php (phpWebSite 0.8.1-CVS gen 2002)
Example: generation of a box with a Yes/No select-option form
$title = "Test form";
$content = "<form method=\"post\" action=\"admin.php\">\n";
$content .= form_options(0,"option","test_yesno",array("1","TRANSLATE[[Yes]]","0","TRANSLATE[[No]]"), 1);
$content .= "</form>";
top of page
Create clever items tables for Admin panels with itemfuncs
itemfuncs is a way to generate items tables with built-in Add/Edit/Delete capabilities in Admin panels without having to write code for them: you only need a field in the db schema; itemfuncs will require you only ONE line of code.
The itemfuncs system only have one public function, all the work is done behind the scenes.
Function prototype: configuration_table_items($itemtype,$itemtype_mod,$location,$prefix,$backpoint)
Return: this function does not return, it creates and display a thememainbox() containing resulting HTML code
- $itemtype : usually this is a MIME-style identifier (like text/value,image/value,...) btw you can also use this also as an own id
- $itemtype_mod : itemtype modifier: if set to 0 it will cause $itemtype/ (MIME-style id string) to be _not_ prefixed before each value, so $itemtype will work only as onscreen-label
- $location : db table and field associated with the items list. This is a string like "table:field". Please note that you DO NOT have to include $table_prefix, since itemfuncs will add it for you automatically.
- $prefix : prefix will be assigned to variables during execution of itemfuncs operations
- $backpoint : will be expanded in admin.php?op=$backpoint, it is destination point where itemfuncs functions will land you after all tasks had been accomplished
Location: itemfuncs.php and admin.php (phpWebSite 0.8.1-CVS gen 2002)
Example: see admin/censorship_admin.php
Alessandro Pisani <email@example.com>