April 12
Quando si crea una pagina Web dinamica, è possibile utilizzare script PHP per determinare se è necessario un campo di input in un modulo HTML e applicare un formato stile particolare a quel campo. Questo aiuta a far capire a un utente che il campo è obbligatorio. Ad esempio, è possibile creare uno stile con un colore di sfondo giallo e applicare quello stile solo per i campi obbligatori nel modulo HTML.
1 Creare un tag di stile in HTML con il formato stile per un campo obbligatorio. Posizionare il tag "stile" tra i tag "testa". Ad esempio, digitare:
<! DOCTYPE HTML PUBLIC "- // W3C // DTD XHTML 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> My Web pagina </ title>
<Style>
.required {background-color: # FF0}
</ Style>
</ Head>
<Body>
2 Creare un array che memorizza un flag che indica se un campo è obbligatorio. Ad esempio, digitare:
<? Php
$ Required = array ();
$ Richiesto [ "nome"] = true;
$ Richiesto [ "e-mail"] = true;
$ Richiesto [ "telefono"] = false;
?>
3 Creare un modulo in formato HTML, e utilizzare PHP per aggiungere la formattazione speciale per ogni campo richiesto. Ad esempio, digitare:
<Form>
Nome: <?? Ingresso name = "nome" type = "text" <? Php if ($ necessario [ "nome"]) echo 'class = "necessaria"';> />
E-mail: <?? Ingresso name = tipo "email" = "text" <? Php if ($ necessario [ "email"]) echo 'class = "necessaria"';> />
Telefono: <?? Ingresso name = tipo "telefono" = "text" <? Php if ($ necessario [ "telefono"]) echo 'class = "necessaria"';> />
<Input name = "submit" type = "submit" value = "submit" />
</ Form>
</ Body>
</ Html>