Ciao Ragazzi, sono nuovissimo del forum.
Scrivo e mi sono iscritto perchè un mio amico mi ha chiesto aiuto per un compito di informatica.
Il compito è il seguente:
[LEFT]Svolgeremo questa attività:
- realizzare un modulo (form) di registrazione per un ipotetico evento culturale (ad
esempio un convegno), in cui siano richieste le seguenti informazioni:
nome, cognome, email, indirizzo, città, cap, telefono fisso,
cellulare, nome ente/azienda, posizione lavorativa,
e permesso di trattare i dati ai fini della legge sulla privacy.
nome, cognome, email e cellulare sono campi obbligatori,
quindi da controllare se sono stati immessi dati e se i dati sono congrui
(es. la stringa di email deve contenere un carattere @);
anche il permesso ai fini privacy è obbligatorio.
Una volta controllati i campi, lo script potrà inviare una email di conferma all?utente.
Realizzare la form in una pagina HTML (registrazione.html) e la pagina di controllo in
PHP (controlloreg.php) che controlli i dati messi in ingresso alla form e reagisca di
conseguenza, ciclando in caso di errori fino alla corretta registrazione.
FINE TESTO
Io ho provato a svolgerlo, ma non ho installato un server PHP al momento. Vorrei semplicemente che mi poteste dire gentilmente se ci sono errori. Vi ringrazio in anticipo.
ECCO IL FILE REGISTRAZIONE.HTML:
<?php include('controlloreg.php'); ?>
<html>
<head>
<title>Form di registrazione</title>
</head>
<body>
<h1>Form di Registrazione per ipotetico evento culturale</h1>
<form id="Register" action="controlloreg.php" method="POST" runat="controlloreg.php" disablebuttons="all">
<table cellpadding="2" cellspacing="0" border="0">
<tr>
<td width="130">
<vllabel validators="UserID,UserIDExist" errclass="error" for="UserID" cerrclass="controlerror">
<font color="#FF0000"></font>
Nome: </vllabel>
</td>
<td width="140">
<input name="UserID" type="text" class="control" id="UserID" size="15">
<vlvalidator name="UserID" type="required" control="UserID" errmsg="Non hai inserito il tuo nome">
<vlvalidator name="UserIDExist" type="custom" control="UserID" errmsg="User ID already exist" function="UserIDCheck">
</td>
<td width="300" rowspan="13" valign="top">
<vlsummary class="error" headertext="Error(s) found:" displaymode="bulletlist">
</td>
</tr>
<tr>
<td width="130">
<vllabel validators="UserID,UserIDExist" errclass="error" for="UserID" cerrclass="controlerror">
<font color="#FF0000"></font>
Cognome:</vllabel>
</td>
<td width="140">
<input name="UserID0" type="text" class="control" id="UserID0" size="15">
<vlvalidator name="UserID" type="required" control="UserID" errmsg="Non hai inserito il tuo cognome">
<vlvalidator name="UserIDExist" type="custom" control="UserID" errmsg="User ID already exist" function="UserIDCheck">
</td>
</tr>
<tr>
<td width="130" height="27">
Indirizzo:</td>
<td width="140" height="27">
<input type="text" size="15"></td>
</tr>
<tr>
<td width="130">
Città:</td>
<td width="140">
<input type="text" size="15" name="T1"></td>
</tr>
<tr>
<td width="130">
CAP:</td>
<td width="140">
<input type="text" size="15" name="T2"></td>
</tr>
<tr>
<td width="130">
Telefono fisso:</td>
<td width="140">
<input type="text" size="15" name="T3"></td>
</tr>
<tr>
<td width="130">
<vllabel validators="UserID,UserIDExist" errclass="error" for="UserID" cerrclass="controlerror">
<font color="#FF0000"></font>
Cellulare:</vllabel>
</td>
<td width="140">
<input name="UserID5" type="text" class="control" id="UserID5" size="15">
<vlvalidator name="UserID" type="required" control="UserID" errmsg="Non hai inserito il tuo numero di cellulare">
<vlvalidator name="UserIDExist" type="custom" control="UserID" errmsg="User ID already exist" function="UserIDCheck">
</td>
</tr>
<tr>
<td width="130">
Nome Ente/azienda</td>
<td width="140">
<input type="text" size="15" name="T4"></td>
</tr>
<tr>
<td width="130">
Posizione Lavoratica</td>
<td width="140">
<input type="text" size="15" name="T5"></td>
</tr>
<tr>
<td>
<vllabel errclass="error" validators="EmailReq,Email" for="Email" cerrclass="controlerror">
<font color="#FF0000"></font> E-mail:</vllabel>
</td>
<td>
<input name="Email" type="TEXT" class="control" id="Email" size="15">
<vlvalidator type="required" name="EmailReq" control="Email" errmsg="Non hai inserito la tua E-mail">
<vlvalidator type="format" format="email" name="Email" control="Email" errmsg="E-mail non valida">
</td>
</tr>
<tr>
<td colspan=2>
<input name="Agreement" type="checkbox" id="Agreement" value="1">
Permesso di trattare i dati ai fini della privacy
<vlvalidator type="required" name="Agreement" control="Agreement" errmsg="Non hai dato il permesso al trattamento dei dati ai fini privacy">
</td>
</tr>
<tr>
<td colspan="2">
<p align="center">
<input type="submit" class="control" value="OK">
<input type="reset" class="control" value="Cancella">
</td>
</tr>
<tr>
<td colspan="2">
<font color="#FF0000">* campi obbligatori</font></td>
</tr>
</table>
</form>
</body>
</html>
<?php VDEnd(); ?>
ECCO IL FILE CONTROLLOREG.PHP
<?php
$sDatabase = 'db_name';
$sHostname = 'localhost';
$sPort = 3306;
$sUsername = 'user_name';
$sPassword = 'password';
$sTable = 'Customers';
$rConn = mysql_connect("$sHostname:$sPort", $sUsername, $sPassword) or die(mysql_error());
mysql_select_db($sDatabase);
define('controlloreg_PARSE', false);
include('controlloreg.php');
function UserIDCheck($sValue, &$oStatus)
{
global $sTable;
$sUserID = addslashes($sValue);
$oStatus->bValid = false;
$oStatus->sErrMsg = "User ID '$sValue' already exist";
$sQuery = "SELECT UserID FROM $sTable WHERE UserID = '$sUserID'";
if ($rRecordset = mysql_query($sQuery))
{
$oStatus->bValid = mysql_num_rows($rRecordset) == 0;
mysql_free_result($rRecordset);
}
}
// Funzione per aggiungere o rimuovere slashes
$sUserID = VDFormat($_POST['UserID'], true);
$sQuery = "INSERT INTO $sTable SET UserID = '$sUserID'";
mysql_query($sQuery);
?>
<html>
<head>
<title>Form di registrazione</title>
</head>
<body>
<h1>Form di Registrazione per ipotetico evento culturale</h1>
<p>I tuoi dati sono stati archiviati</p>
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="100">User ID:</td>
<td width="300"><?php echo $_POST['UserID']; ?></td>
</tr>
<tr>
<td>Password:</td>
<td><?php echo $_POST['Password']; ?></td>
</tr>
<tr>
<td>Name:</td>
<td><?php echo $_POST['Name']; ?></td>
</tr>
<tr>
<td>E-mail:</td>
<td><?php echo $_POST['Email']; ?></td>
</tr>
</table>
</body>
</html>
Premesso che ho mezzo copiato alcune parti in giro per internet, per far prima, mi servirebbe sapere se ci sono errori rispetto a quanto richiesto dal TESTO...
VI RINGRAZIO INFINITAMENTE.
Mastro
PS: se riusciste a rispondermi entro domani mi fareste un favore, d'altronde non è nemmeno per me: è per un mio amico, insomma è bello aiutarsi a vicenda. GRAZIE ANCORA.[/LEFT]