par rimie » 19 mai 2011, 20:35
function createForm() { $creerForm = ''; foreach($this->FormField as $k=>$v) { $creerForm .= $v; } if(preg_match('/type="file"/', $creerForm)) { echo 'file exists<br>'; $form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'" enctype="'.$this->enctype.'" enccccccccccc>'; } else { echo 'file do not exists<br>'; $form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'" nooooooooooo>'; } echo $form; echo $creerForm;
par rimie1 » 19 mai 2011, 17:06
public final function __construct($name, $method='', $action='', $enctype='') { //codes $this->FormField[] = array( 'type' => "form", 'name' => $name, 'method' => $method, 'action' => $action); } function createForm() { if(preg_match('/type="file"/', $this->FormField[$k])) { $form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'" enctype="'.$this->enctype.'">'; } else { $form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'">'; } echo $form; foreach($this->FormField as $k=>$v) { echo $v; }
par xTG » 19 mai 2011, 13:33
$this->FormField[] = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'">';
$this->FormField[] = array( 'type' => "form", 'name' => $name, 'method' => $method, 'action' => $action);
par rimie1 » 19 mai 2011, 13:25
Ton gros souci en fait c'est que tu créés des Strings avec tes méthodes add alors qu'il faudrait créer une structure qui sera ensuite mise en forme dans le createForm().
Pour ton problème faudrait parcourir une fois le tableau pour placer le enctype et ensuite parcourir une seconde fois le tableau pour générer les champs.
foreach($this->FormField as $k=>$v) { // place le enctype } foreach($this->FormField as $k=>$v) { // generer les champs }
par xTG » 19 mai 2011, 13:10
par rimie1 » 19 mai 2011, 12:27
function createForm() { foreach($this->FormField as $k=>$v) { if(preg_match('/type="file"/', $this->FormField[$k])) { $form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'" enctype="'.$this->enctype.'">'; } else { $form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'">'; } echo $form; echo $v; } }
par xTG » 18 mai 2011, 08:04
par rimie1 » 17 mai 2011, 20:36
Quel problème ? Celui de l'enctype ? Comme je te l'ai dit il suffit de faire un simple test pour savoir quoi mettre...
<?php // 1ere de la tag form public final function __construct($name, $method='', $action='', $enctype='') $this->FormField[] = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'">'; // 2eme: inputs public final function addInput($type, $name='', $value='') //3eme creation du formulaire function createForm() { foreach($this->FormField as $k=>$v) { echo $v; } } ?>
$this->FormField[] = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'" enctype="'.$this->enctype.'">';
par xTG » 17 mai 2011, 08:07
par rimie1 » 16 mai 2011, 23:55
par rimie1 » 14 mai 2011, 09:30
Tu as une variable $Formulaire->enctype donc il suffit de la modifier avec la fonction addInput() lorsque tu ajoutes un input file.
par xTG » 13 mai 2011, 08:04
par rimie1 » 13 mai 2011, 01:16
<?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(); ?>
par xTG » 12 mai 2011, 08:10
par rimie1 » 12 mai 2011, 04:09
Puisque je te dis que la structure nous importe peu... On se fiche du contenu de l'array, ce qu'on veut c'est l'index du dernier élément. Relis mon code à tête reposée car visiblement tu n'as rien compris de ce que je t'ai proposé.
<form name='nomForm' method='POST' action='' enctype=''> Label1: <input type='text' name='a1' class="c1"><br> Label2: <input type='text' name='a2' value='valeur2'><span></span> Label3: <input type='password' name='p1'><br> Label4: <input type='file' name='f1'><br>