Index du Forum » » SFORM

Auteur

SForm et date
Pascal
415      

  Posté : 27-02-2003 15:54

Bon...
Enlevé la fonction add_date, on se sert de add_field :

function add_field($name,$en, $value='', $type='text', $obligation=false, $size='50', $diviseur='5', $ctrl='') {
if ($type=="submit") {$name=$this->submit_value;}
if ($type=="date") {$size=10; $ctrl='date';}

$this->form_fields[count($this->form_fields)]=array(
'name'=>$name,
'type'=>$type,
'en'=>$en,
'value'=>$value,
'size'=>$size,
'diviseur'=>$diviseur,
'obligation'=>$obligation,
'ctrl'=>$ctrl
);
}

Dans print_form rajoute :

case 'date':
$str.="<tr class=\"text\"><td class=\"text\">".$this->form_fields[$i]['en'];
$style = "text";
// Si la date initial est nulle on en crée une à la date du jour
if ($this->form_fields[$i]['value']=="") $this->form_fields[$i]['value']=date("d/m/Y");
// Si key_close, pas la peine de dire que c'est un champs obligatoire
if($this->form_fields[$i]['obligation'] && $this->form_key_status!="close"){
$this->form_check.=" && (f.elements['".$this->form_fields[$i]['name']."'].value!='')" ;
$style = "oblig";
$str.=" <font color=red>*</font><td>";
} else $str.="<td>";

// Charge la valeur et analyse la clef
if ($this->form_fields[$i]['name']==$this->form_key) {
$this->form_key_value=$this->form_fields[$i]['value'];
if ($this->form_key_status=="close") {
$str.="<input type=hidden name='".$this->form_fields[$i]['name']."' value='".$this->form_fields[$i]['value']."'>";
$str.="<b>".$this->form_fields[$i]['value']."</b> ";
} else {
$str.="<input class=$style type=".$this->form_fields[$i]['type']." name='".$this->form_fields[$i]['name']."' value='".$this->form_fields[$i]['value']."' size=".($this->form_fields[$i]['size']+1)." maxlength=".$this->form_fields[$i]['size'].">";
}
} else {
$str.="<input class=$style type=".$this->form_fields[$i]['type']." name='".$this->form_fields[$i]['name']."' value='".$this->form_fields[$i]['value']."' size=".($this->form_fields[$i]['size']+1)." maxlength=".$this->form_fields[$i]['size'].">";
}
break;

Dans make_response :

case 'date':
if ($this->form_fields[$i]['ctrl']!="") {
$this->control($this->form_fields[$i]['name'],$this->form_fields[$i][' en'],$GLOBALS[$this->form_fields[$i]['name']],$this->form_fields[$i]['ctr l']);
}
// Charge la valeur de la clef puisqu'on peut indexer sur la date pourquoi pas
if ($this->form_fields[$i]['name']==$this->form_key) {
$this->form_key_value=$GLOBALS[$this->form_fields[$i]['name']];
}
$this->answer[$i].="<DATE>\n";
$this->answer[$i].="<".$this->form_fields[$i]['name']." >".$GLOBALS[$this->form_fields[$i]['name']]."</".$this- >form_fields[$i]['name'].">\n";
$this->answer[$i].="</DATE>";
break;

Aff_response (pas de changement) :

case 'date':
$str.="<tr bgcolor=$bg><td>".$this->form_fields[$i]['en'];
$str.="<td>";
$str.="<b>".$GLOBALS[$this->form_fields[$i]['name']]."  </b>";
break;

Dans control :

case 'date':
// Date en tableau
$date = explode("/",$valeur);
if (!checkdate($date[1],$date[0],$date[2])) {
$this->error($nom,"Date non valide");
exit ();
}
break;

Je crois que c'est mieux que le premier


[ Message édité par : Pascal : 27-02-2003 15:54 ]



Cet article provient de NPDS

http://www.npds.org/viewtopic.php?topic=4509&forum=19