par
rimie1 » 21 avr. 2011, 04:54
rebonjour Nicolas,
je l'ai fait d'une autre facon, je n'aime pas copier/coller les codes, et je voudrais apprendre:
<?php
class Formulaire {
// Toutes les propriétés du formulaire
private $form = array();
private $method; // POST et GET
private $action;
private $name;
private $value;
private $type = array(); // text, password, button, submit, radio, checkbox
private $id;
private $class;
private $size;
private $maxlength;
private $cols;
private $rows;
private $enctype;
private $typeLoop;
######################################## Form Start #############################
public final function __construct($name, $method='', $action='', $enctype='') { //name est obligatoire
$this->name = $name;
$this->method = $method;
$this->action = $action;
$this->enctype = $enctype;
} // end __construct function
######################################## Form End #############################
######################################## Inputs Start #############################
public final function addInput($type, $name='', $value='', $size='', $maxlength='', $checked=''){ // type est obligatoire
$this->type = $type;
$this->name = $name;
$this->value = $value;
$this->size = $size;
$this->maxlength = $maxlength;
$this->checked = $checked;
$this->type = array('file', 'password');
}// end addInput function
####################################### Inputs End #############################
######################################## Generate Form Start #############################
public final function generateForm()
{
echo 'enctype'.$this->enctype.'<br>';
// l'entete du formulaire
if($this->enctype)
{
//echo $enctype;
$form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'" '.$this->enctype.'>';
}
else
{
$form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'">';
}
foreach($this->type as $typeLoop)
{
echo $typeLoop.'<br>';
// les inputs
switch($typeLoop)
{
case 'password':
$form .= '<input type="'.$this->type.'" name="'.$name.'" value="'.$value.'" size="'.$size.'" maxlength="' .$maxlength.'" id="'.$id.'" class="'.$class.'" />';
break;
case 'hidden':
$form .= '<input type="'.$this->type.'" name="'.$name.'" value="'.$value.'" />';
break;
case 'file':
$form .= '<input type="'.$this->type.'" name="'.$name.'" />';
break;
// par defaut un text
default:
$form .= '<input type="text" name="'.$name.'" value="'.$value.'" size="'.$size.'" maxlength="'.$maxlength.'" id="'.$id.'" class="'.$class.'" />';
} // end switch
return $form;
}
}// end foreach
######################################## Generate Form End #############################
} // end class
$f = new Formulaire('monForm1', '', '', 'ici je vais mettre enctype');
$f->addInput('file', 'nomFile', 'valeur'); // file upload
$f->addInput('password', 'nomFile', 'valeur'); // file upload
echo $f->generateForm();
?>
le probleme dans mon code:
+ Il genere le formulaire avec l'input file,
+ Il met taitau type 'Array'
Code : Tout sélectionner
enctypeici je vais mettre enctype<br>file<br><form name="nomFile" method="" action="" ici je vais mettre enctype><input type="Array" name="" />
rebonjour Nicolas,
je l'ai fait d'une autre facon, je n'aime pas copier/coller les codes, et je voudrais apprendre:
[php]
<?php
class Formulaire {
// Toutes les propriétés du formulaire
private $form = array();
private $method; // POST et GET
private $action;
private $name;
private $value;
private $type = array(); // text, password, button, submit, radio, checkbox
private $id;
private $class;
private $size;
private $maxlength;
private $cols;
private $rows;
private $enctype;
private $typeLoop;
######################################## Form Start #############################
public final function __construct($name, $method='', $action='', $enctype='') { //name est obligatoire
$this->name = $name;
$this->method = $method;
$this->action = $action;
$this->enctype = $enctype;
} // end __construct function
######################################## Form End #############################
######################################## Inputs Start #############################
public final function addInput($type, $name='', $value='', $size='', $maxlength='', $checked=''){ // type est obligatoire
$this->type = $type;
$this->name = $name;
$this->value = $value;
$this->size = $size;
$this->maxlength = $maxlength;
$this->checked = $checked;
$this->type = array('file', 'password');
}// end addInput function
####################################### Inputs End #############################
######################################## Generate Form Start #############################
public final function generateForm()
{
echo 'enctype'.$this->enctype.'<br>';
// l'entete du formulaire
if($this->enctype)
{
//echo $enctype;
$form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'" '.$this->enctype.'>';
}
else
{
$form = '<form name="'.$this->name.'" method="'.$this->method.'" action="'.$this->action.'">';
}
foreach($this->type as $typeLoop)
{
echo $typeLoop.'<br>';
// les inputs
switch($typeLoop)
{
case 'password':
$form .= '<input type="'.$this->type.'" name="'.$name.'" value="'.$value.'" size="'.$size.'" maxlength="' .$maxlength.'" id="'.$id.'" class="'.$class.'" />';
break;
case 'hidden':
$form .= '<input type="'.$this->type.'" name="'.$name.'" value="'.$value.'" />';
break;
case 'file':
$form .= '<input type="'.$this->type.'" name="'.$name.'" />';
break;
// par defaut un text
default:
$form .= '<input type="text" name="'.$name.'" value="'.$value.'" size="'.$size.'" maxlength="'.$maxlength.'" id="'.$id.'" class="'.$class.'" />';
} // end switch
return $form;
}
}// end foreach
######################################## Generate Form End #############################
} // end class
$f = new Formulaire('monForm1', '', '', 'ici je vais mettre enctype');
$f->addInput('file', 'nomFile', 'valeur'); // file upload
$f->addInput('password', 'nomFile', 'valeur'); // file upload
echo $f->generateForm();
?>
[/php]
le probleme dans mon code:
+ Il genere le formulaire avec l'input file,
+ Il met taitau type 'Array'
[code]enctypeici je vais mettre enctype<br>file<br><form name="nomFile" method="" action="" ici je vais mettre enctype><input type="Array" name="" />[/code]