[PHP5] MyForm V1.0
Auteur: Stijn - 10 februari 2006 - 18:17 - Gekeurd door: nemesiskoen - Hits: 7383 - Aantal punten: 3.92 (6 stemmen)
Uitleg:
Met deze volledige class (enkel voor PHP 5x servers) kan je complexe en gewone formulieren ontwerpen. Zo kan je blijven in PHP werken ipv je PHP tag te sluiten een streepje code en dan in je HTML dan nog eens PHP zetten om vervolgens terug PHP te beginnen...
[PLUS]
Je kan sneller en meer werken, niet overtuigd? Heb je pech
Installatie:
1) Je included de class file
2) je maakt een nieuw object aan ($obj = new MyForm(..); ) en je zet er de nodige parameters in -> zie class script!!!
3) Je maakt je formulier maar zonder HTML - TAGS ertussen, wanneer je deel of je formulier af is doe je $obj->ParseForm(); zodat je bijvoorbeeld een <BR> kan stoppen om nog een veld eronder te zetten.
4) Wanneer je helemaal gedaan hebt zet je op het einde dan $obj->EndForm();
Meer uitleg:
1) Zie voorbeeld bestand (kan geen voorbeeld online zetten omdat online servers op PHP4x draaien)
2) PM me gerust
Have fun
|
Code: |
MyForm.inc.php (class script)
<?php
/**
MyForm.INC.PHP
A EXTENDED CLASS THAT BUILD YOUR SITE
Writer: Stijn - [PSF]*B*oOsTer
Date: 06 - 02 - 2006
Team: PHP Source Fighters © 2006
Right 2 use this shit[?] and to share :-)
Have fun
The [PSF]-Team
**/
###################################
######### EVENTS LEGEND #########
# {key} : {value} #
###################################
# 0 : onclick #
# 1 : ondblclick #
# 2 : onkeydown #
# 3 : onkeypress #
# 4 : onkeyup #
# 5 : onmousedown #
# 6 : onmouseover #
# 7 : onmousemove #
# 8 : onmouseout #
# 9 : onmouseup #
# 10 : onreset #
# 11 : onsubmit #
###################################
class MyForm
{
/**
@var protected array Events
@var protected array FormData
@var protected array enctypes
@var protected empty F_Action
@var protected empty F_Method
@var protected empty F_Name
@var protected empty F_Enctype
*/
public $Events = array ( 'onclick' , 'ondblclick' , 'onkeydown' , 'onkeypress' , 'onkeyup' , 'onmousedown' , 'onmouseover' , 'onmousemove' , 'onmouseout' , 'onmouseup' , 'onreset' , 'onsubmit' );
public $FormData = array ( );
public $enctypes = array ( 'multipart/form-data' , 'text/plain' , 'application/x-www-form-urlencoded' );
/**
__construct( );
@param string action
@param string method
@param string name
@param string enctype standard value: text/plain
@param array events
*/
public function __construct( $action , $method , $name , $enctype = 'multipart/form-data' , $events = array() )
{
( in_array( $enctype , $this->enctypes ) === false ) ? die('Your enctype is wrong') : '' ;
( $method != 'GET' && $method != 'POST' ) ? die('Wrong method: POST <-> GET') : '';
( !isset( $action ) || empty( $action ) ) ? die('Enter a action') : '';
$FormData = '<form action='.$action.' method='.$method.' name='.$name.' enctype='.$enctype;
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
$FormData .= ' ' . $this->Events[ $key ] . '=' . $value;
}
}
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputText( );
@param string name
@param string value
@param int size
@param int maxLength
@param int readonly
@param int disabled
@param array events
*/
public function InputText( $name , $value , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() )
{
$FormData = '<input type=text name='.$name;
( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : '';
( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : '';
( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : '';
( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputPassword( );
@param string name
@param string value
@param int size
@param int maxLength
@param int readonly
@param int disabled
@param array events
*/
public function InputPassword( $name , $value , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() )
{
$FormData = '<input type=password name='.$name;
( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : '';
( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : '';
( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : '';
( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputHidden( );
@param string name
@param string value
@param int size
@param int maxLength
@param int readonly
@param int disabled
@param array events
*/
public function InputHidden( $name , $value , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() )
{
$FormData = '<input type=hidden name='.$name;
( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : '';
( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : '';
( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : '';
( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputCheckbox( );
@param string name
@param string value
@param int size
@param int maxLength
@param int checked
@param int readonly
@param int disabled
@param array events
*/
public function InputCheckbox( $name , $value , $checked = 0 , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() )
{
$FormData = '<input type=checkbox name='.$name;
( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : '';
( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : '';
( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : '';
( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
( isset($checked) && !empty( $checked ) && is_numeric( $checked ) === true ) ? $FormData .= ' checked=checked' : '';
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputRadio( );
@param string name
@param string value
@param int size
@param int maxLength
@param int checked
@param int readonly
@param int disabled
@param array events
*/
public function InputRadio( $name , $value , $checked = 0 , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() )
{
$FormData = '<input type=radio name='.$name;
( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : '';
( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : '';
( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : '';
( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
( isset($checked) && !empty( $checked ) && is_numeric( $checked ) === true ) ? $FormData .= ' checked=checked' : '';
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputFile( );
@param string name
@param string value
@param int size
@param int maxLength
@param int readonly
@param int disabled
@param array events
*/
public function InputFile( $name , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() )
{
$FormData = '<input type=file name='.$name;
( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : '';
( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : '';
( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputImage( );
@param string name
@param string src
@param string alst
@param int size
@param int maxLength
@param int readonly
@param int disabled
@param array events
*/
public function InputImage( $name , $src , $alt = '' , $readonly = 0 , $disabled = 0 , $events = array() )
{
$FormData = '<input type=image name='.$name;
( isset($src) && !empty( $src ) ) ? $FormData .= ' src='.$src : die('You have to enter a source!');
( isset($alt) && !empty( $alt ) ) ? $FormData .= ' alt='.$alt : '';
( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputButton( );
@param string name
@param string value
@param int disabled
@param array events
*/
public function InputButton( $name , $value , $disabled = 0 , $events = array() )
{
$FormData = '<input type=button name='.$name;
( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputReset( );
@param string name
@param string value
@param int disabled
@param array events
*/
public function InputReset( $name , $value , $disabled = 0 , $events = array() )
{
$FormData = '<input type=reset name='.$name;
( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
InputSubmit( );
@param string name
@param string value
@param int disabled
@param array events
*/
public function InputSubmit( $name , $value , $disabled = 0 , $events = array() )
{
$FormData = '<input type=submit name='.$name;
( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
$FormData .= '>';
$this->FormData[] = $FormData;
return true;
}
/**
Select( );
@param string name
@param int rows
@param int multiple
@param array options
@param int disabled
@param array events
*/
public function Select( $name , $rows = 1 , $multiple = 0 , $options = array() , $disabled = 0 , $events = array() )
{
$FormData = '<select name='.$name.' rows='.$rows;
( $multiple === 1 ) ? $FormData .= ' multiple=multiple' : '';
( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : '';
$FormData .= '>';
//add options
if( count( $options ) > 0 ) {
foreach( $options as $value ) {
/**
* Every key has an array with the next values
##########################
######### LEGEND #########
##########################
# 0 : value #
# 1 : text #
# 2 : selected ( 0 | 1 ) #
##########################
*/
$FormData .= '<option value='.$value[0];
( $value[2] === 1 ) ? $FormData .= ' selected=selected' : '';
$FormData .= '>';
$FormData .= $value[1];
$FormData .= '</option>';
}
}
if( count( $events ) > 0 ) {
foreach( $events as $key => $value ) {
( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ;
}
}
//close select
$FormData .= '</select>';
$this->FormData[] = $FormData;
return true;
}
/**
ParseForm( );
*/
public function ParseForm()
{
foreach($this->FormData as $value) {
echo $value;
}
$this->FormData = array( ); //make empty
}
/**
EndForm( );
*/
function EndForm()
{
$this->FormData[] = '</form>';
foreach($this->FormData as $value) {
echo $value;
}
$this->FormData = array( ); //make empty
}
}
?>
<?php /** MyForm.INC.PHP A EXTENDED CLASS THAT BUILD YOUR SITE Writer: Stijn - [PSF]*B*oOsTer Date: 06 - 02 - 2006 Team: PHP Source Fighters © 2006 Right 2 use this shit[?] and to share :-) Have fun The [PSF]-Team **/ ################################### ######### EVENTS LEGEND ######### # {key} : {value} # ################################### # 0 : onclick # # 1 : ondblclick # # 2 : onkeydown # # 3 : onkeypress # # 4 : onkeyup # # 5 : onmousedown # # 6 : onmouseover # # 7 : onmousemove # # 8 : onmouseout # # 9 : onmouseup # # 10 : onreset # # 11 : onsubmit # ################################### class MyForm { /** @var protected array Events @var protected array FormData @var protected array enctypes @var protected empty F_Action @var protected empty F_Method @var protected empty F_Name @var protected empty F_Enctype */ public $Events = array ( 'onclick' , 'ondblclick' , 'onkeydown' , 'onkeypress' , 'onkeyup' , 'onmousedown' , 'onmouseover' , 'onmousemove' , 'onmouseout' , 'onmouseup' , 'onreset' , 'onsubmit' ); public $FormData = array ( ); public $enctypes = array ( 'multipart/form-data' , 'text/plain' , 'application/x-www-form-urlencoded' ); /** __construct( ); @param string action @param string method @param string name @param string enctype standard value: text/plain @param array events */ public function __construct ( $action , $method , $name , $enctype = 'multipart/form-data' , $events = array() ) { ( in_array( $enctype , $this->enctypes ) === false ) ? die('Your enctype is wrong') : '' ; ( $method != 'GET' && $method != 'POST' ) ? die('Wrong method: POST <-> GET') : ''; ( !isset( $action ) || empty( $action ) ) ? die('Enter a action') : ''; $FormData = '<form action='.$action.' method='.$method.' name='.$name.' enctype='.$enctype; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { $FormData .= ' ' . $this->Events[ $key ] . '=' . $value; } } $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputText( ); @param string name @param string value @param int size @param int maxLength @param int readonly @param int disabled @param array events */ public function InputText ( $name , $value , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() ) { $FormData = '<input type=text name='.$name; ( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : ''; ( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : ''; ( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : ''; ( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputPassword( ); @param string name @param string value @param int size @param int maxLength @param int readonly @param int disabled @param array events */ public function InputPassword ( $name , $value , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() ) { $FormData = '<input type=password name='.$name; ( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : ''; ( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : ''; ( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : ''; ( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputHidden( ); @param string name @param string value @param int size @param int maxLength @param int readonly @param int disabled @param array events */ public function InputHidden ( $name , $value , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() ) { $FormData = '<input type=hidden name='.$name; ( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : ''; ( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : ''; ( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : ''; ( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputCheckbox( ); @param string name @param string value @param int size @param int maxLength @param int checked @param int readonly @param int disabled @param array events */ public function InputCheckbox ( $name , $value , $checked = 0 , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() ) { $FormData = '<input type=checkbox name='.$name; ( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : ''; ( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : ''; ( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : ''; ( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } ( isset($checked) && !empty( $checked ) && is_numeric( $checked ) === true ) ? $FormData .= ' checked=checked' : ''; $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputRadio( ); @param string name @param string value @param int size @param int maxLength @param int checked @param int readonly @param int disabled @param array events */ public function InputRadio ( $name , $value , $checked = 0 , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() ) { $FormData = '<input type=radio name='.$name; ( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : ''; ( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : ''; ( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : ''; ( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } ( isset($checked) && !empty( $checked ) && is_numeric( $checked ) === true ) ? $FormData .= ' checked=checked' : ''; $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputFile( ); @param string name @param string value @param int size @param int maxLength @param int readonly @param int disabled @param array events */ public function InputFile ( $name , $size = 15 , $maxLength = 999 , $readonly = 0 , $disabled = 0 , $events = array() ) { $FormData = '<input type=file name='.$name; ( isset($size) && !empty( $size ) && is_numeric( $size ) === true ) ? $FormData .= ' size='.$size : ''; ( isset($maxLength) && !empty( $maxLength ) && is_numeric( $maxLength ) === true ) ? $FormData .= ' maxLength='.$maxLength : ''; ( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputImage( ); @param string name @param string src @param string alst @param int size @param int maxLength @param int readonly @param int disabled @param array events */ public function InputImage ( $name , $src , $alt = '' , $readonly = 0 , $disabled = 0 , $events = array() ) { $FormData = '<input type=image name='.$name; ( isset($src) && !empty( $src ) ) ? $FormData .= ' src='.$src : die('You have to enter a source!'); ( isset($alt) && !empty( $alt ) ) ? $FormData .= ' alt='.$alt : ''; ( isset($readonly) && !empty( $readonly ) && is_numeric( $readonly ) === true ) ? $FormData .= ' readonly='.$readonly : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputButton( ); @param string name @param string value @param int disabled @param array events */ public function InputButton ( $name , $value , $disabled = 0 , $events = array() ) { $FormData = '<input type=button name='.$name; ( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputReset( ); @param string name @param string value @param int disabled @param array events */ public function InputReset ( $name , $value , $disabled = 0 , $events = array() ) { $FormData = '<input type=reset name='.$name; ( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** InputSubmit( ); @param string name @param string value @param int disabled @param array events */ public function InputSubmit ( $name , $value , $disabled = 0 , $events = array() ) { $FormData = '<input type=submit name='.$name; ( isset($value) && !empty( $value ) ) ? $FormData .= ' value='.$value : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } $FormData .= '>'; $this->FormData[] = $FormData; return true; } /** Select( ); @param string name @param int rows @param int multiple @param array options @param int disabled @param array events */ public function Select ( $name , $rows = 1 , $multiple = 0 , $options = array() , $disabled = 0 , $events = array() ) { $FormData = '<select name='.$name.' rows='.$rows; ( $multiple === 1 ) ? $FormData .= ' multiple=multiple' : ''; ( isset($disabled) && !empty( $disabled ) && is_numeric( $disabled ) === true ) ? $FormData .= ' disabled='.$disabled : ''; $FormData .= '>'; //add options if( count( $options ) > 0 ) { foreach( $options as $value ) { /** * Every key has an array with the next values ########################## ######### LEGEND ######### ########################## # 0 : value # # 1 : text # # 2 : selected ( 0 | 1 ) # ########################## */ $FormData .= '<option value='.$value[0]; ( $value[2] === 1 ) ? $FormData .= ' selected=selected' : ''; $FormData .= '>'; $FormData .= $value[1]; $FormData .= '</option>'; } } if( count( $events ) > 0 ) { foreach( $events as $key => $value ) { ( isset( $key) && !empty( $key ) ) ? $FormData .= ' '.$this->Events[ $key ] . '=' . $value : '' ; } } //close select $FormData .= '</select>'; $this->FormData[] = $FormData; return true; } /** ParseForm( ); */ public function ParseForm() { foreach($this->FormData as $value) { } $this->FormData = array( ); //make empty } /** EndForm( ); */ function EndForm() { $this->FormData[] = '</form>'; foreach($this->FormData as $value) { } $this->FormData = array( ); //make empty } } ?>
Voorbeeld.php
<?
include('MyForm.inc.php');
$obj = new MyForm($_SERVER['PHP_SELF'] , 'POST' , 'testform');
$obj->InputText('TextField' , 'Stijn' , 17 , 999 , 1 );
$obj->ParseForm();
echo "<br><br>";
$obj->InputRadio('my_Text' , 'stijn' , 1, 40 , 999 , 0 , 0 , array('', 'alert("hallo");') );
$obj->InputRadio('my_Text', 'jeroen');
$obj->ParseForm();
echo "<br><br>";
$obj->InputImage('Image', 'image.png' , 'test' , 50);
$obj->ParseForm();
echo "<br><br>";
$obj->InputButton('Button', 'KnopTekst' , 0 , array(6 => 'alert("goeiedag");'));
$obj->ParseForm();
echo "<br><br>";
$obj->Select('Select°1' , 5 , 1 ,
array (
array('WMP' , 'Windows Media Player' , 1) ,
array('BG' , 'Bill Gates' , 0) ,
array('MS' , 'Microsoft', 0 ),
array('N44Bs' , 'Noobs' , 0)
));
$obj->EndForm();
?>
<? include('MyForm.inc.php'); $obj = new MyForm($_SERVER['PHP_SELF'] , 'POST' , 'testform'); $obj->InputText('TextField' , 'Stijn' , 17 , 999 , 1 ); $obj->ParseForm(); $obj->InputRadio('my_Text' , 'stijn' , 1, 40 , 999 , 0 , 0 , array('', 'alert("hallo");') ); $obj->InputRadio('my_Text', 'jeroen'); $obj->ParseForm(); $obj->InputImage('Image', 'image.png' , 'test' , 50); $obj->ParseForm(); $obj->InputButton('Button', 'KnopTekst' , 0 , array(6 => 'alert("goeiedag");')); $obj->ParseForm(); $obj->Select('Select°1' , 5 , 1 , array('WMP' , 'Windows Media Player' , 1) , array('BG' , 'Bill Gates' , 0) , array('MS' , 'Microsoft', 0 ), array('N44Bs' , 'Noobs' , 0) )); $obj->EndForm(); ?>
Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|