Ciao ragazzi,
Avrai bisogno di realizzare un form suddiviso in più pagine, quindi con degli step intermedi che alla fine portano all'ultima pagina in cui appare il pulsante invia.
Ho trovato un paio di esempi su come usare i campi 'hidden' e le sessioni, ma non funzionano (forse perchè sono costretto ad utilizzare gli echo?). Comunque un altro problema sta nel fatto che le pagine non sono altro che id definiti in una singola pagina.
Forse è meglio postare tutto il codice per farmi capire meglio: (io ho riassunto tutto il codice per semplificare)
Codice PHP:
<?
$id=$_GET[id];
// ################### CONFIG ###################
$class_txt = "text";
$class_inputbutton = "inputButton";
$class_inputline = "inputLine";
$class_inputfield = "inputField";
$style_inputline = "width:355px;";
$style_inputfield = "width:355px;";
// email
$target_address = "info@email.it";
$email_subject = "Oggetto";
// error messages
$err_name = "nome";
$err_email = "e-mail";
$err_tit = "titolo";
// misc text
$msg_date = "Date";
$msg_name = "Nome";
$msg_email = "Email:";
$msg_tit = "Titolo ";
$txt_send = "Invia";
$txt_mandatory = "obbligatorio";
$msg_indent = 11;
// messages
$txt_thankyou = "<div class='$class_txt'><h2>Grazie!</h2></div>";
$txt_error = "<div style='color: #cc3300' class='$class_txt'><h2>Si sono verificati i seguenti errori:</h2>{errors}</div>"; // {errors} is replaced by the errors that occurred
// ################ END CONFIG #################
function spaces($num, $fill=" "){
$foo="";
for ($i=0; $i<$num; $i++) $foo.=$fill;
return $foo;
}
function isValidEmail($addr){
if(eregi("^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\\.[a-z]{2,4}$", $addr))
return true;
else
return false;
}
// start form evaluation
$error="foo";
if ($_REQUEST['do']=="send"){
$error=false;
if ($_REQUEST['name']=="") $error.="» $err_name
";
if ($_REQUEST['tit']=="") $error.="» $err_tit
";
if (!isValidEmail($_REQUEST['email'])) $error.="» $err_email
";
if ($error===false){
$message="$msg_date:".spaces($msg_indent-strlen($msg_date)).date("d M Y, H:i", time());
if ($_REQUEST['name']) $message.="\n$msg_name:".spaces($msg_indent-strlen($msg_name)).$_REQUEST['name'];
if ($_REQUEST['tit']) $message.="\n$msg_tit:".spaces($msg_indent-strlen($msg_tit)).$_REQUEST['tit'];
$message.="\n$msg_email:".spaces($msg_indent-strlen($msg_email))."mailto:".$_REQUEST['email'];
$message.="\n\n$msg_request:\n\n".$_REQUEST['message'];
mail($target_address, $email_subject, $message, "From: ".$_REQUEST['email']);
echo $txt_thankyou;
}else if ($error!==false) $error=str_replace("{errors}", $error, $txt_error);
}
if ($error!==false){
if($error!="foo") echo $error;
// form
echo "<script language='JavaScript' type='text/JavaScript'>\n";
echo "window.onload = function(){ document.form1.firma.focus(); }\n";
echo "</script>\n";
echo "<form name='form1' method='post' action=''>\n";
echo "<h2>FORM</h2>\n";
if ($id == '1') {
echo "<table border='0' class='txt'>\n";
echo "<tr><td class='$class_txt'>$msg_name *</td>\n";
echo "<td><input name='name' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['name']."'>\n";
echo "</td></tr>\n";
echo "</table>\n";
}
else if ($id == '2') {
echo "<table border='0' class='txt'>\n";
echo "<tr><td class='$class_txt'>$msg_tit *</td>\n";
echo "<td><input name='tit' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['tit']."'>\n";
echo "</td></tr>\n";
echo "</table>\n";
}
else {
echo "<table border='0' class='txt'>\n";
echo "<tr><td class='$class_txt'>$msg_email *</td>\n";
echo "<td><input name='email' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['email']."'>\n";
echo "</td></tr>\n";
echo "<tr><td><input name='Submit' type='Submit' class='$class_inputbutton' value='$txt_send'>\n";
echo "<input name='do' type='hidden' id='do' value='send'></td>\n";
echo "</tr>\n";
echo "</table>\n";
}
echo "</form>\n";
}
?>