<?php /* * Site : www.ajornet.com * But : Ecriture de formulaires en PHP * * Copyright (c) 2001 Ajornet http://www.ajornet.com/ * Auteur : Daniel Lucazeau mailto:daniel.lucazeau@ajornet.com * * $Id: formulaire.class.php,v 1.6 2001-06-11 11:37:39+02 lucazeau_daniel Exp lucazeau_daniel $ * */
///////////////////////////////////////////////////////////////////////////// /////// Classe de base /////// ///////////////////////////////////////////////////////////////////////////// class ctrlDF { ///////////////////////////////////////////////////////////////////////////// /////// Fonctions et variables privées /////// ///////////////////////////////////////////////////////////////////////////// var $szNomChamp = ""; // Nom du champ var $szTxtChamp = ""; // Texte anonçant le champ dans le formulaire (optionnel) explications var $szValChamp = ""; // Valeur du champ var $szTitChamp = ""; // Libellé explicite pour l'internaute var $htmlString = ""; // Chaîne du HTML pour avoir le controle // Pour plus tard var $bChampRequired = ""; // Obligatoire/optionel var $bOnchange = ""; // Gestion de onChange etc.. var $szStyle = ""; // Style à utiliser
function ctrlDF ( $n="", $v="", $l="", $t="", $s="") { // Constructeur $this->setNom( $n); $this->setVal( $v); $this->setTit( $l); $this->setTxt( $t); $this->setSty( $s); }
function calcHtml() { $this->htmlString = "";} ///////////////////////////////////////////////////////////////////////////// /////// Fonctions publiques /////// ///////////////////////////////////////////////////////////////////////////// function getVal () {return $this->szValChamp;} function setVal ( $v) {$this->szValChamp = $v;}
function getNom () {return $this->szNomChamp;} function setNom ( $n) {$this->szNomChamp = $n;}
function getTit () {return $this->szLibChamp;} function setTit ( $l) {$this->szLibChamp = $l;}
function getTxt () {return $this->szTxtChamp;} function setTxt ( $t) {$this->htmlForm['txt'] = $this->szTxtChamp = $t;}
function getSty () {return $this->szStyle;} function setSty ( $s) {$this->szStyle = $s;}
function getHtml() { if ( func_num_args() !=0) { $this->calcHtml( func_get_arg(0)); } else { $this->calcHtml(); } return $this->htmlString; }
function getAllHtml ( $brk=0, $nBr=0) { $this->calcHtml( $nBr); return ( $this->getTit() .( $brk?"<br>":"") .$this->htmlString); } function afficheChamp ( $brk=0, $nBr=0) { $this->calcHtml(); printf( $this->getTit() .( $brk?"<br>":"") .$this->htmlString); } function stringChamp () { $this->calcHtml(); return $this->htmlForm['chp'] = $this->htmlString; }
} // fin de ctrlDF ///////////////////////////////////////////////////////////////////////////// /////// Classes privées /////// ///////////////////////////////////////////////////////////////////////////// class ctrlUniCbRbDF extends ctrlDF { // Check-box et radio-boutons var $bChecked; var $szType;
function ctrlUniCbRbDF( $t, $n, $v, $l, $c, $s) { $this->ctrlDF( $n, $v, $l, '', $s); $this->bChecked = $c; $this->szType = $t; }
function calcHtml () { if ( $this->szStyle != '') { $szLibChamp = sprintf( '<span class="%s">%s</span>', $this->szStyle, $this->szLibChamp); } else { $szLibChamp= $this->szLibChamp; } $this->htmlString = sprintf( "<INPUT TYPE='%s' NAME='%s' VALUE='%s' %s>%s", $this->szType, $this->szNomChamp, $this->szValChamp, ( $this->bChecked ? 'CHECKED': ''), $szLibChamp); } } // fin de ctrlUniCbRbDF
class ctrlUniCbDF extends ctrlUniCbRbDF { // Check-box
function ctrlUniCbDF( $nom, $val, $lib, $chk) { $this->ctrlUniCbRbDF( "checkbox", $nom, $val, $lib, $chk); } } // Fin de ctrlUniCbDF
class ctrlUniRbDF extends ctrlUniCbRbDF { // Radio-Boutons
function ctrlUniRbDF( $nom, $val, $lib, $chk) { $this->ctrlUniCbRbDF( "radio", $nom, $val, $lib, $chk); } } // Fin de ctrlUniRbDF
class ctrlGrpCbRbDF extends ctrlDF { // privée var $szType; var $aValLib; var $szChecked = array();
function ctrlGrpCbRbDF ( $typ, $nom, $valib, $vck, $titre, $style="") {
$this->ctrlDF( $nom, "", $titre, "", $style); $this->szType = $typ; $this->aValLib = $valib; if ( is_array( $vck)) { $this->szChecked = $vck; } else { $this->szChecked = array( $vck); } }
function calcHtml( $nBr=1) { //$nBr nombre de Rb/Cb par ligne $str = "<table><tr>"; $cpt=0; foreach ( $this->aValLib as $val=>$lib) { $cpt++; $x = new ctrlUniCbRbDF( $this->szType, $this->szNomChamp, $val, $lib, in_array( $val, $this->szChecked), $this->szStyle); $str .= "<td>".$x->stringChamp()."</td>"; if ( $nBr > 0) $str .= ( ( $cpt%$nBr == 0) ? "</tr><tr>" : ""); } $str = ereg_replace( "</tr><tr>$", "", $str); $this->htmlString = $str."</tr></table>"; } } // fin de ctrlGrpCbRbDF
class ctrlInputDF extends ctrlDF { // zone de texte standard var $szType; var $iSize; var $iMaxLength;
function ctrlInputDF ( $t, $n, $v, $l, $iSize, $iMaxLength) { $this->ctrlDF( $n, $v, $l); $this->szType = $t; settype( $iSize, "integer"); $this->iSize = $iSize; settype( $iMaxLength, "integer"); $this->iMaxLength = $iMaxLength; }
function calcHtml () { $this->htmlString = sprintf("<INPUT TYPE='%s' SIZE= %d MAXLENGTH=%d NAME='%s' VALUE=\"%s\">", $this->szType, $this->iSize, $this->iMaxLength, $this->szNomChamp, $this->szValChamp); } } // fin de ctrlInputDF
class ctrlDdLbDF extends ctrlDF { // Liste déroulante var $aValLib; var $szChecked = array();
// $nom : nom du TAG // $valib tableaux dont les index associatifs sont les valeurs du TAG et function ctrlDdLbDF ( $nom="", $iSize=1, $bMulti=false, $valib="", $vck="", $titre="") { $this->ctrlDF( $nom, "", $titre); $this->aValLib = $valib; $this->bMulti=$bMulti; if ( is_array( $vck)) $this->szChecked = $vck; else $this->szChecked = array( $vck); $this->szSize = "SIZE=$iSize"; }
function calcHtml() { $str = sprintf("<SELECT NAME='%s' %s %s>", $this->szNomChamp, $this->szSize, ( $this->bMulti? "MULTIPLE" :"")); while (list ($val, $lib) = each ( $this->aValLib)) { $str .= sprintf("<OPTION VALUE='%s' %s>%s", $val, ( in_array( $val, $this->szChecked)? "SELECTED": ""), $lib); } $this->htmlString = $str . "</SELECT>"; }
} // fin de ctrlDdLbDF ///////////////////////////////////////////////////////////////////////////// /////// Classes publiques /////// ///////////////////////////////////////////////////////////////////////////// class ctrlTextDF extends ctrlInputDF{
function ctrlTextDF ( $n="", $v="", $l="", $iSize=40, $iMaxLength=40) { $this->ctrlInputDF( "text", $n, $v, $l, $iSize, $iMaxLength); } } // fin de ctrlTextDF
class ctrlPswdDF extends ctrlInputDF{
function ctrlPswdDF ( $n="", $v="", $l="", $iSize=40, $iMaxLength=40) { $this->ctrlInputDF( "password", $n, $v, $l, $iSize, $iMaxLength); } }
class ctrlHiddenDF extends ctrlDF {
function ctrlHiddenDF( $n="", $v="") { $this->ctrlDF( $n, $v); }
function calcHtml () { $this->htmlString = sprintf("<INPUT TYPE='hidden' NAME='%s' VALUE='%s'>", $this->szNomChamp, $this->szValChamp); } } // fin de ctrlHiddenDF
class ctrlGrpCbDF extends ctrlGrpCbRbDF {
function ctrlGrpCbDF ( $nom="", $valib="", $vck="", $titre="", $style="") { $this->ctrlGrpCbRbDF( "checkbox", $nom.'[]', $valib, $vck, $titre, $style); } } // Fin de ctrlGrpCbDF
class ctrlGrpRbDF extends ctrlGrpCbRbDF {
function ctrlGrpRbDF ( $nom="", $valib="", $vck="", $titre="", $style="") { $this->ctrlGrpCbRbDF( "radio", $nom, $valib, $vck, $titre, $style); } } // Fin de ctrlGrpRbDF
class ctrlDropDownDF extends ctrlDdLbDF { // Liste déroulante
function ctrlDropDownDF ( $nom="", $valib="", $vck="", $titre="") { $this->ctrlDdLbDF ( $nom, 1, false, $valib, $vck, $titre); } } // fin de ctrlDropDownDF
class ctrlListBoxDF extends ctrlDdLbDF { // Zone de liste
function ctrlListBoxDF ( $nom="", $iSize=10, $bMulti=false, $valib="", $vck="", $titre="") { $this->ctrlDdLbDF ( $nom.'[]', $iSize, $bMulti, $valib, $vck, $titre); } } // fin de ctrlDropDownDF
class ctrlTextAreaDF extends ctrlDF { var $iRow; var $iCol; var $typeWrap;
function ctrlTextAreaDF ( $n="", $r=2, $c=40, $v="", $w="", $titre="") { $this->ctrlDF ( $n, $v, $titre); $this->iRow = $r; $this->iCol = $c; $this->setWrap( $w); }
function setWrap( $w="") { $this->typeWrap = ""; switch ( $w) { case "v": $this->typeWrap = "WRAP=virtual"; break; case "p": $this->typeWrap = "WRAP=physical"; break; default: $this->typeWrap = ""; break; } }
function calcHtml () { $sz = sprintf( "<TEXTAREA NAME='%s' COLS='%s' ROWS='%s' %s>", $this->szNomChamp, $this->iCol, $this->iRow, $this->typeWrap); $sz .= sprintf( "%s</TEXTAREA>", $this->szValChamp); $this->htmlString = $sz; } } // Fin de ctrlTxtAreaDF ?>
Télécharger le code de la classe
|