Html Quick Form
Scritto da Roberto Vespa, 31-10-2009 20:26
Valuazione utenti    (0 voto)
Pagina vista 1582
Favoriti 73

HTML_QUICKFORM

Questo sezione è una semplice introduzione a una parte di PEAR, HTML_QuickForm. Non è da considerarsi esaustiva; infatti, copre una piccola parte delle funzionalità totali di HTML_QuickForm. E' per giunta non definitiva: questa regole sono prese dal codice sorgente stesso, e sono ovviamente sempre giuste. In ogni caso, per i novizi a PEAR o HTML_QuickForm, il testo seguente dovrebbe essere un utile fondamento su cui costruire il resto


IL FORM (Un esempio semplice ed esplicativo)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testing PEAR HTML_QuickForm</title>
</head>
<body>
<?php
require_once "HTML/QuickForm.php";
$form = new HTML_QuickForm('frmTest', 'get');
$form->addElement('text', 'txtNome', ‘Nome:');
$form->addElement('reset', 'btnClear', 'Annulla:');
$form->addElement('submit', 'btnSubmit', 'Invia:');
$form->addRule('txtNome','Campo richiesto', 'required');
if ($form->validate()) {
$form->freeze();
}

$form->display();
?>
</body>
</html>

SPIEGAZIONE DEL CODICE.

require_once "HTML/QuickForm.php";

Carica la dichiarazione della classe QuickForm

$form = new HTML_QuickForm('frmTest', 'get');

Istanza di un oggetto HTML_QuickForm

Questo vuol dire che il form assumerà il nome: ‘frmTest’ e che il metodo per il passaggio dei dati dal form html allo script php sarà di tipo ‘get’

$form->addElement('text', 'txtNome', ‘Nome:');

Crea un elemento di un form.

L’elemento del form in questione sarà di tipo ‘text’ assumerà il nome di ‘txtNome’ e la sua label sarà: ‘Nome’

$form->addRule('txtNome','Campo richiesto', 'required'); oppure:
$form->addRule('txtNome','Campo richiesto', 'required',’’,’client’);

Obbligatorietà del campo.

Questa riga ci dice che il campo ‘txtNome’ è un campo obbligatorio e la label mostrata all’utente sarà: ‘Campo richiesto’

Oltre a required di seguito sono illustrati altri tipi di validazioni

* required
* maxlength
* rangelength
* regex
* email
* emailorblank
* lettersonly
* alphanumeric
* numeric
* nopunctuation
* nonzero

Altro esempio di addRule

$form->addRule(‘cap’,‘Lunghezza massima 8 caratteri','maxlength',8,'client');
if ($form->validate()) {
$form->freeze();
}

Validazione form

HTML_QuickForm introduce anche il concetto di validazione di un form

Con $form->freeze(); i dati vengono congelati prima che vengano rivisualizzati.

$form->display();

Mostra a video il disegno del form

 

TABELLA DEGLI ELEMENTI

BUTTON

addElement(
'button',
’Nome del bottone’,
’Testo del bottone’,
’ Stringa o array di attributi’
);

CHECKBOX

AddElement(
'checkbox',
’Nome del checkbox’,
’Label prima del checkbox’,
’Label dopo del checkbox’,
’Stringa o array di attributi’
);
 

 

DATE

addElement(
'date',
'Name',
'Label',
$options
);
 
 
 
 
 
 
$options = array(
        'language'  => 'en',
        'format'    => 'dMYHi',
        'minYear'   => 2001,
        'maxYear'   => 2005
        );
Possibili valori del format string   
 
D = Nome abbreviato del giorno
l = Nome esteso del giorno
d = Numero del giorno
M = Nome corto del mese
F = Nome esteso del mese
m = Numero del mese
Y = 4 cifre dell’anno
h = Formato ora 12
H = Formato ora 24
i = Minuti
s = Secondi
a = am/pm
A = AM/PM

 

FILE

addElement(
'file',
name elemento file’,
’label elemento file’,
’stringa o array di attributi
);

 

HEADER

addElement(
'header',
name of header’,
’Testo dell header
);

 

HIDDEN

addElement(
'hidden',
nome elemento hidden’,
’valore elemento hidden’,
’stringa o array di attributi

);

IMAGE

addElement('image',
nome per l’immagine’,
’file sorgente per l’immagine’,
’stringa o array di attributi’
);

LINK

addElement(
'link',
nome per il link’,
’label per il campo link’,
’URL del link’,
’testo da visualizzare’,
’stringa o array da visualizzare
);

PASSWORD

addElement(
'password',
nome per campo password’,
’label per campo password’,
’stringa o array di attributi’
);
 

RADIO

addElement(
'radio',
nome per pulsante radio’,
’testo visualizzato prima del pulsante’,
’testo visualizzato dopo il pulsante’,
’valore restituito’,
’stringa di array o attributi’
);
 

RESET

addElement(
'reset',
nome del pulsante reset’,
’testo del pulsante’,
’stringa o array di attributi’
);

SELECT

addElement(
'select',
nome della select’,
’label della select’,
’dati della select’,
’stringa o array di attributi’
);

STATIC

addElement(
'static',
label elemento static’,
’testo da visualizzare’
);

SUBMIT

addElement(
'submit',
nome pulsante submit’,
’testo del pulsante’,
’stringa o array di attributi’
);
 

TEXTAREA

addElement(
'textarea',
nome del campo textarea’,
’label’,
’stringa o array di attributi’
);
        
 

Ultimo aggiornamento: 26-11-2009 17:40

Pubblicato in : Tutorial, PHP
Tags : metodo per il passaggio dei dati, Obbligatorietà del campo, validazione di un form
Commenti utente Cita quest'articolo sul tuo sito web Favoriti Invia ad un amico Salva su del.icio.us Articoli correlati Leggi tutto...

PEC

ordina_ora

News Letter

Iscrivendoti, potrai ricevere sulla tua e mail le nostre promozioni.

Area riservata