Ho creato un form che controlla i campi grazie ad una serie di controlli if nidificati; per renderlo più snello, ho usato gli "include" per inserire parti di codice.
Il problema è che il form funziona solo fino ad un certo punto: da lì in avanti sembra non prendere in considerazione quello che ho scritto.
Il primo controllo è sui dati dei campi input text e lì funziona;
Il secondo controllo è sulle categorie di utenti e lì funziona;
A seconda della categoria, compare una tabella di prezzi da selezionare con dei check buttons.
Subito sotto, il bottone submit per calcolare l'importo: ecco, lì non funziona più.
Per avere un'idea di come si presenta il form, ecco un link provvisorio: http://www.pieromazzini.com/siem
Purtroppo, non so come si fa a conservare i dati immessi dagli utenti nel form dopo aver cambiato pagina, cioè, se qualcuno non ha messo un dato in un campo dove era obbligatorio, compare una pagina di errore in html che lo avvisa. Ritornando alla pagina del form, i dati scompaiono.
Il codice, invece, è parecchio lungo ma lo scrivo lo stesso:
---------------------
<?
include("functions/funzioni_mms.php");
$step = $_POST['go'];
?>
<html>
<head>
<title>Form MMS</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="reg_form.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="forms.js"></script>
</head>
<body>
<form action="index.php" method="post" id="formMMS1" name="formMMS1">
<div id="container">
<?
if ($step == "Go to Step 2 »") {
$giorno = date("d");
$mese = date("m");
$anno = date("y");
$paper = $_POST['paper'];
$titolo = $_POST['titolo'];
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$org = $_POST['org'];
$citta = $_POST['citta'];
$nazione = $_POST['nazione'];
$zip = $_POST['zip'];
$tel = $_POST['tel'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$radio = $_POST['radio'];
//Controllo i dati dei campi input text del form
include("include/checkdata.php");
//Se il controllo è andato a buon fine, verifico che un radio button della sezione Category sia selezionato;
// Se lo è, allora:
if ($radio != "") {
include("include/checkcat.php");
//Se invece il radio button non è selezionato, mostro un messaggio di errore
} else {
print "<script language='JavaScript' type='text/JavaScript'>
location.href='error/error_category.html';</script>";
}
?><div id="bottone"><input type="submit" name="go" id="go" value="Calculate amount »"></div><?
if($step == "Calculate amount »") {
$check1 = $_POST['check1'];
$check2 = $_POST['check2'];
$check3 = $_POST['check3'];
$check4 = $_POST['check4'];
if ($radio == "normale") {
include("include/normal_fees.php");
}
elseif ($radio == "membro") {
include("include/member_fees.php");
}
elseif ($radio == "studente") {
include("include/student_fees.php");
}
elseif ($radio == "studmembro") {
include("include/studentmemb_fees.php");
}
}
} else {
?>
<fieldset class="in">
<legend>General data:</legend>
<label for="paper" class="req" accesskey="a" title="Access key: [a]">PAPER ID (if applicable): <input id="paper" name="paper"></label>
<label for="titolo" class="req" accesskey="b" title="Access key: ">*Title: <input id="titolo" name="titolo"></label>
<label for="nome" class="req" accesskey="c" title="Access key: [c]">*First name: <input id="nome" name="nome"></label>
<label for="cognome" class="req" accesskey="d" title="Access key: [d]">*Last name: <input id="cognome" name="cognome"></label>
<label for="org" class="req" accesskey="e" title="Access key: [e]">*Company/Organization: <input id="org" name="org"></label>
<label for="citta" class="req" accesskey="f" title="Access key: [f]">*Town: <input id="citta" name="citta"></label>
<label for="nazione" class="req" accesskey="g" title="Access key: [g]">*Country: <input id="nazione" name="nazione"></label>
<label for="zip" class="req" accesskey="h" title="Access key: [h]">*ZIP Code: <input id="zip" name="zip"></label>
<label for="tel" class="req" accesskey="i" title="Access key: [i]">*Phone: <input id="tel" name="tel" maxlength="80"></label>
<label for="fax" class="req" accesskey="j" title="Access key: [j]">Fax: <input id="fax" name="fax" maxlength="80"></label>
<label for="email" class="req" accesskey="k" title="Access key: [k]">*E-mail: <input id="email" name="email" maxlength="150"></label>
<strong class="asterisco">* Mandatory fields</p>
</fieldset>
<fieldset id="checkCat">
<legend>Category:</legend>
<label for="norm"><input id="norm" name="radio" type="radio" value="normale">Normal</label>
<label for="member"><input id="member" name="radio" type="radio" value="membro">Member</label>
<label for="student"><input id="student" name="radio" type="radio" value="studente">Student</label>
<label for="studMemb"><input id="studMemb" name="radio" type="radio" value="studmembro">Student Member</label>
</fieldset>
<fieldset id="checkMember">
<legend>Membership:</legend>
<label for="iee"><input id="iee" name="iee" type="checkbox">IEE</label>
<label for="euma"><input id="euma" name="euma" type="checkbox">EuMA</label>
<label for="siem"><input id="siem" name="siem" type="checkbox">SIEm</label>
<div id="number">
<label for="membnumb" accesskey="l" title="Access key: [l]">Member no. (if applicable)<input id="membnumb" name="membnumb" type="text"></label>
</div>
</fieldset>
<div id="bottone"><input name="go" type="submit" id="go" value="Go to Step 2 »">
</div>
<?
}
?>
</div>
</form>
</body>
</html>
------------------------
Trascrivo anche il file include "normal_fees.php" che è identico, nella struttura, a "member_fees.php", "student_fees.php" e a "studentmemb_fees.php":
------------------------
<?
/*###### Tariffe e calcolo dei costi per l'utente Normal #####*/
if ($mese <= 05) {
if ($check1 == "checkbox") { $check1 = 400; } else { $check1 = 0; }
if ($check2 == "checkbox") { $check2 = 70; } else { $check2 = 0; }
if ($check3 == "checkbox") { $check3 = 10; } else { $check3 = 0; }
if ($check4 == "checkbox") { $check4 = 50; } else { $check4 = 0; }
} else {
if ($check1 == "checkbox") { $check1 = 475; } else { $check1 = 0; }
if ($check2 == "checkbox") { $check2 = 70; } else { $check2 = 0; }
if ($check3 == "checkbox") { $check3 = 10; } else { $check3 = 0; }
if ($check4 == "checkbox") { $check4 = 50; } else { $check4 = 0; }
print "$check1
";
print "$check2
";
print "$check3
";
print "$check4
";
$tot = $check1+$check2+$check3+$check4;
print "<table summary=\"This table shows the total due according to the user categories: normal (not member), member, student and student member\" class=\"tariffe\">\r\n";
print "<tr class=\"row1\">\r\n";
print "<td class=\"total\">Total due: $tot<span>€</span></td>\r\n";
print "</tr>\r\n";
print "</table>\r\n";
}
?>
------------------------
E' proprio questa la parte che non funziona.
Spero che qualcuno mi possa aiutare
Grazie, un saluto a tutti.
Piero