/*
------------- Formulaires ---------------
Principe objet, sauf que les noms des champs représentent exactement ta BD...
Usage :
include_once("class.forms.php4");
$form_inscription = new Forms("form_inscription", // nom du formulaire
"traitement_inscription.php", // page action
"POST"); // méthode d'envoi
$form_inscription->create_form();
$form_inscription->create_table("table_css_class", // une pseudo class CSS2 pour ton tableau
"Titre du tableau"); // titre affiché au début du formulaire
$form_inscription->create_input_type("text", // type : text ou password
"Prénom", // légende ça sera affiché comme ça : Prénom : [ ] (en gros)
"client_prenom", // nom dans la BD
20, // nombre de caractères (c'est la size en HTML)
"clients", // nom de la table MySQL
NULL, // valeur par défaut
"bleu"; // style css pour l'écriture du formulaire
$form_inscription->close_table();
$form_inscription->close_form();
/*
Voilà, tu as ton form près à être envoyé. Regarde la doc interne pour
une meilleure compréhension, mais là, déjà tu comprends le principe.
Source / Exemple :
<?php
class Forms{
var $name=NULL;
var $action=NULL;
var $method=NULL;
var $number_of_file=0;
var $forms_dao_db = NULL;
function Forms($name,$action,$method){
$this->name=$name;
$this->action=$action;
$this->method=$method;
$this->number_of_file=0;
$this->forms_dao_db = new DAO();
}
function create_form(){
?>
<form name="<?php echo $this->name;?>" id="<?php echo $this->name;?>" method="<?php echo $this->method;?>" action="<?php echo $this->action;?>" enctype="multipart/form-data">
<?php
}
function close_form(){
?>
</form>
<?php
}
function create_table($class,$title){
?>
<table class="<?php echo $class;?>">
<?php
if (!is_null($title)) {
?>
<tr>
<th colspan="3"><?php echo $title;?></th>
</tr>
<?php
}
}
function close_table(){
?>
</table>
<?php
}
function create_fieldset($name){
?>
<fieldset>
<legend><?php echo $name;?></legend>
<?php
}
function close_fieldset(){
?>
</fieldset>
<?php
}
function getMaxLength($field,$table){
$this->forms_dao_db->DAO_query("DESC $table");
for($i=0;$i<$this->forms_dao_db->DAO_numrows();$i++)
{
$val=$this->forms_dao_db->DAO_fetch_array();
if ($field==$val["Field"])
{
$p=strpos($val["Type"],"(");
$d=strpos($val["Type"],")");
if ($p && $d)
{
$l=$d-$p;
$max=substr($val["Type"],$p+1,$l-1);
}
}
}
return $max;
}
/**
- create_input_type($cit_type,$cit_legend,$cit_name,$cit_size, $cit_maxlength, $cit_value)
- Type : text,password
- legend : Text shown
- name : name of the input
- size : size of the input
- maxlength : max length of the input
- value : default value NULL
- class : css style for this input
- /
function create_input_type($cit_type,$cit_legend,$cit_name,$cit_size, $cit_table, $cit_value, $cit_class){
$cit_maxlength = $this->getMaxLength($cit_name,$cit_table);
if (is_null($cit_class)) {
$cit_class="general_forms";
}
?>
<tr>
<td class="tdright"><?php echo $cit_legend;?></td>
<td>:</td>
<td class="tdleft"><input class="<?php echo $cit_class;?>" type="<?php echo $cit_type;?>" name="<?php echo $cit_name;?>" id="<?php echo $cit_name;?>" size="<?php echo $cit_size;?>" maxlength="<?php echo $cit_maxlength;?>" value="<?php echo $cit_value;?>" /></td>
</tr>
<?php
}
function create_input_hidden($cih_name,$cih_value){
?>
<input type="hidden" name="<?php echo $cih_name;?>" id="<?php echo $cih_name;?>" value="<?php echo $cih_value;?>" />
<?php
}
/**
- create_input_date($cid_legend,$cid_form_name,$cid_name,$cid_size,$cid_maxlength,$cid_value,$cid_style)
- Params:
- legend : Text displayed
- form_name : The name of the current form
- name : The name of the field
- size : The size of the field
- maxlength : The maximum length
- value : The default value
- style : The style to apply
- /
function create_input_date($cid_legend,$cid_form_name,$cid_name,$cid_size,$cid_maxlength,$cid_value,$cid_class){
if (is_null($cid_class)) {
$cid_class="general_forms";
}
js_open_calendar(); // javascript
?>
<tr>
<td class="tdright"><?php echo $cid_legend;?></td>
<td>:</td>
<td class="tdleft">
<table>
<tr>
<td colspan="3"><input class="<?php echo $cid_class;?>" type="text" name="<?php echo $cid_name;?>" id="id_<?php echo $cid_name;?>" size="<?php echo $cid_size;?>" maxlength="<?php echo $cid_maxlength;?>" value="<?php echo $cid_value;?>" onfocus="javascript:openCalendar('<?php echo $cid_form_name;?>','<?php echo $cid_name;?>','date')" /></td>
</tr>
<tr class="trcenter">
<td><a title="<?php echo "Ouvrir Calendrier";?>" href="javascript:openCalendar('<?php echo $cid_form_name;?>','<?php echo $cid_name;?>','date')"><img src="images/cal.png" border="0" width="16" height="16" alt="Cal" title="<?php echo "Calendrier";?>" /></a></td>
<td><a title="<?php echo "Date d'aujourd'hui";?>" href="javascript:void(0)" onclick="javascript:document.getElementById('id_<?php echo $cid_name;?>').value='<?php echo date("d/m/Y");?>'"><img src="images/today.png" border="0" width="16" height="16" alt="T!" title="<?php echo "Date d'aujourd'hui";?>" /></a></td>
<td><a title="<?php echo "Effacer le contenu de la cellule";?>" href="javascript:void(0)" onclick="javascript:document.getElementById('id_<?php echo $cid_name;?>').value=''"><img src="images/red_drop.png" title="<?php echo "Effacer le contenu de la cellule";?>" align="bottom" alt="X" width="16" height="16" border="0" /></a></td>
</tr>
</table>
</td>
</tr>
<?php
}
function create_radio($cr_legend,$cr_name,$cr_array_values,$cr_value,$cr_class){
if (is_null($cr_class)) {
$cr_class="general_forms";
}
?>
<tr>
<td class="tdright"><?php echo $cr_legend;?></td>
<td>:</td>
<td class="tdleft">
<table>
<?php
$cr_cpt=0;
foreach($cr_array_values as $cr_array_values_key){
$cr_cpt++;
?>
<tr>
<td><input class="<?php echo $cr_class;?>" type="radio" name="<?php echo $cr_name;?>" id="<?php echo $cr_name.$cr_cpt;?>" value="<?php echo $cr_array_values_key["value"];?>"<?php if ($cr_array_values_key["value"]==$cr_value) {echo " checked=\"checked\"";}?> /></td>
<td><label for="<?php echo $cr_name.$cr_cpt;?>"><?php echo $cr_array_values_key["legend"];?></label></td>
</tr>
<?php
} //foreach
?>
</table>
</td>
</tr>
<?php
} //creat_radio
function create_textarea($ct_legend,$ct_name,$ct_cols,$ct_rows,$ct_value,$ct_class){
if (is_null($ct_class)) {
$ct_class="general_forms";
}
?>
<td class="tdright"><?php echo $ct_legend;?></td>
<td>:</td>
<td class="tdleft">
<textarea cols="<?php echo $ct_cols;?>" rows="<?php echo $ct_rows;?>" name="<?php echo $ct_name;?>" id="<?php echo $ct_name;?>" class="<?php echo $ct_class;?>"><?php echo $ct_value;?></textarea>
</td>
<?php
}
/**
- $cs_legend
- $cs_name
- $cs_table_id
- $cs_table_name
- $cs_table
- $cs_value
- $cs_class
- /
function create_select($cs_legend,$cs_name,$cs_table_id,$cs_table_name,$cs_table,$cs_value,$cs_class){
if (is_null($cs_class)) {
$cs_class="general_forms";
}
?>
<tr>
<td class="tdright"><?php echo $cs_legend;?></td>
<td>:</td>
<td class="tdleft">
<select name="<?php echo $cs_name;?>" id="<?php echo $cs_name;?>" class="<?php echo $cs_class;?>">
<option class="two"></option>
<?php
$this->forms_dao_db->DAO_query("SELECT $cs_table_id,$cs_table_name FROM $cs_table");
$i=0;
while($val=$this->forms_dao_db->DAO_fetch_assoc()){
$i++;
?>
<option <?php echo ($i%2==0)?"class=\"two\" ":"class=\"one\" ";?>value="<?php echo $val[$cs_table_id];?>"<?php if ($val[$cs_table_id]==$cs_value){echo " selected=\"selected\"";}?>><?php echo $val[$cs_table_name];?></option>
<?php
}
?>
</select>
</td>
</tr>
<?php
}
function create_checkbox($cc_legend,$cc_name,$cc_value,$cc_script,$cc_class){
if (is_null($cc_class)) {
$cc_class="general_forms";
}
?>
<tr>
<td class="tdright"><?php echo $cc_legend;?></td>
<td>:</td>
<td class="tdleft">
<input type="checkbox" name="<?php echo $cc_name;?>" id="<?php echo $cc_name ?>" class="<?php echo $cc_class;?>"<?php if ($cc_value=="on") {echo " checked=\"checked\"";}?> <?php echo $cc_script;?>/>
<label for="<?php echo $cc_name;?>"><?php echo $cc_legend;?></label>
</td>
</tr>
<?php
}
function create_hint($ct_hint){
?>
<tr>
<td class="hint" colspan="3"><?php echo $ct_hint;?></td>
</tr>
<?php
}
function create_button($cb_button){
?>
<tr>
<td colspan="3" class="buttons">
<?php buttons($cb_button);?>
</td>
</tr>
<?php
}
}
?>
26 juin 2006 à 15:14
<label for="le_champ">Le champ</label>
L'accessibilité c'est important en xhtml donc le clique sur le nom du champ doit mettre le focus sur le champ.
PS: je garde le paramètre name et non pas id car sur les radio et les checkbox tu te retrouve avec plusieurs balise qui possède le même id ce qui n'est pas autorisé.
26 juin 2006 à 09:10
Sinon, un petit article sympa sur les formulaires et XHTMl :
http://www.openweb.eu.org/articles/formulaire_accessible/
26 juin 2006 à 00:47
Comment allez vous à ce propos ?
Moi je me fait réopéré Jeudi 29 courant donc pas top surtout au niveau du parlodel ... mais bon ... mes benchs sont enfin bon et cela fait du bien ...
Sjón
25 juin 2006 à 22:17
@ tchaOo°
25 juin 2006 à 19:18
un formulaire XHTML mis en forme dans un tableau...? Argh..le W3C s'en retournerait dans sa tombe. S'il était mort.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.