par
rimie1 » 13 mai 2011, 01:16
voila, le saut de ligne c'est fait, ca marche comme je le veux:
<?php
class Formulaire {
// Toutes les propriétés du formulaire
######################################## Form Start ###############################
public final function __construct($name, $method='', $action='', $enctype='')
{
$this->name = $name;
$this->method = $method;
$this->action = $action;
$this->enctype = $enctype;
$this->FormField[] = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'" enctype="'.$this->enctype.'">';
}
######################################## Inputs Start #############################
public final function addInput($type, $name='', $value='')
{
$this->type = $type;
$this->name = $name;
$this->value = $value;
Switch($this->type)
{
case 'text':
$this->FormField[] .= '<input type="'.$this->type.'" value="'.$this->value.'">';
break;
case 'password':
$this->FormField[] .= '<input type="'.$this->type.'" value="valPass">';
break;
case 'file':
$this->FormField[] .= '<input type="'.$this->type.'">';
break;
} // EnD Switch
} // EnD Function
public final function addTextarea($name)
{
$this->FormField[] .= '<textarea name="'.$name.'" cols="20" rows="5">okokok</textarea>';
}
######################################## Seperation Start #############################
// separation des champs
public function Separation()
{
$this->FormField[] .= "<br />";
}
######################################## Seperation End #############################
######################################## Inputs Start #############################
function createForm()
{
foreach($this->FormField as $k=>$v)
{
echo $v;
}
}
} // EnD class
$frm = new Formulaire('formName', 'met', 'act', 'enc');
$frm->addInput('text', 'nom1', 'valeur1');
$frm->addInput('text', 'nom2', 'valeur2');
$frm->Separation();
$frm->addInput('file', 'nom2', 'valeur2');
$frm->Separation();
$frm->addTextarea('', '', '');
$frm->Separation();
$frm->addInput('text', 'nom3', 'valeur3');
echo $frm->createForm();
?>
le seul soucis c'est de verifier si un input de type file existe pour que la form comporte l'attribut enctype, sinon on ne l'ajoute pas.
voila, le saut de ligne c'est fait, ca marche comme je le veux:
[php]
<?php
class Formulaire {
// Toutes les propriétés du formulaire
######################################## Form Start ###############################
public final function __construct($name, $method='', $action='', $enctype='')
{
$this->name = $name;
$this->method = $method;
$this->action = $action;
$this->enctype = $enctype;
$this->FormField[] = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'" enctype="'.$this->enctype.'">';
}
######################################## Inputs Start #############################
public final function addInput($type, $name='', $value='')
{
$this->type = $type;
$this->name = $name;
$this->value = $value;
Switch($this->type)
{
case 'text':
$this->FormField[] .= '<input type="'.$this->type.'" value="'.$this->value.'">';
break;
case 'password':
$this->FormField[] .= '<input type="'.$this->type.'" value="valPass">';
break;
case 'file':
$this->FormField[] .= '<input type="'.$this->type.'">';
break;
} // EnD Switch
} // EnD Function
public final function addTextarea($name)
{
$this->FormField[] .= '<textarea name="'.$name.'" cols="20" rows="5">okokok</textarea>';
}
######################################## Seperation Start #############################
// separation des champs
public function Separation()
{
$this->FormField[] .= "<br />";
}
######################################## Seperation End #############################
######################################## Inputs Start #############################
function createForm()
{
foreach($this->FormField as $k=>$v)
{
echo $v;
}
}
} // EnD class
$frm = new Formulaire('formName', 'met', 'act', 'enc');
$frm->addInput('text', 'nom1', 'valeur1');
$frm->addInput('text', 'nom2', 'valeur2');
$frm->Separation();
$frm->addInput('file', 'nom2', 'valeur2');
$frm->Separation();
$frm->addTextarea('', '', '');
$frm->Separation();
$frm->addInput('text', 'nom3', 'valeur3');
echo $frm->createForm();
?>
[/php]
le seul soucis c'est de verifier si un input de type file existe pour que la form comporte l'attribut enctype, sinon on ne l'ajoute pas.