Ciao,
ho un problema con l'invio di un form in php, nello specifico con un radio button.
Fin quando non ho inserito il radio button del consenso tutto funzionava, ora, non so se si inserisce così, anche se seleziono il radio button per il consenso mi rimane l'avviso che devo selezionare il radio button se no il modulo non viene inviato.
Dove sbaglio?
<?
// CSS classes & styles
$class_txt = "font:normal 11px Helvetica, Arial, SansSerif;";
$class_inputbutton = "inputButton";
$class_inputline = "inputLine";
$class_inputfield = "inputField";
$style_inputline = "width:355px;";
$style_inputfield = "width:355px;";
$target_address = "info@gmail.com";
$email_subject = "Richiesta informazioni dal sito web";
// error messages
$err_name = "Per favore inserisci il nome.";
$err_surname = "Per favore inserisci il cognome.";
$err_phone = "Per favore inserisci il numero di telefono.";
$err_msg = "Per favore inserisci la richiesta.";
$err_email = "Per favore inserisci un indirizzo email valido.";
$err_consenso = "Per favore dai il consenso al trattamento dei dati.";
// misc text - modificare il testo rosso per i parametri sul sito
$msg_date = "Data";
$msg_name = "Nome";
$msg_surname = "Cognome";
$msg_company = "Azienda";
$msg_sectore = "Settore di Attività";
$msg_address = "Indirizzo";
$msg_city = "Cap./Città/Paese";
$msg_phone = "Telefono";
$msg_email = "Email";
$msg_phone = "Consenso";
/*$msg_answerby = "Reply by";*/
$txt_email = "Email";
$txt_phone = "Telefono";
$txt_post = "Post";
$txt_send = "Invia";
$txt_mandatory = "campi obbligatori";
$txt_consenso = "Consenso";
$msg_request = "Richiesta informazioni";
$msg_indent = 11;
// messages
$txt_thankyou = "<div style='position:absolute; left:40px; top:250px; width:350px; height:60px; z-index:1; color: #000000' class='$class_txt'><h2>Grazie per averci contattato!</h2><h3>Ti risponderemo appena possibile.</h3></div>";
$txt_error = "<div style='position:absolute; left:250px; top:40px; width:350px; z-index:1; color: #cc3300' class='$class_txt'><h4>Per inviare la richiesta è necessario:</h4><h4>{errors}</h4></div>"; // {errors} is replaced by the errors that occurred
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['surname']=="") $error.="» $err_surname
";
if ($_REQUEST['fon']=="") $error.="» $err_phone
";
if ($_REQUEST['message']=="") $error.="» $err_msg
";
if (!isValidEmail($_REQUEST['email'])) $error.="» $err_email
";
if ($_REQUEST['consenso']=="") $error.="» $err_consenso
";
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['surname']) $message.="\n$msg_surname:".spaces($msg_indent-strlen($msg_surname)).$_REQUEST['surname'];
if ($_REQUEST['firma']) $message.="\n$msg_company:".spaces($msg_indent-strlen($msg_company)).$_REQUEST['firma'];
if ($_REQUEST['sectore']) $message.="\n$msg_sectore:".spaces($msg_indent-strlen($msg_sectore)).$_REQUEST['sectore'];
if ($_REQUEST['adresse']) $message.="\n$msg_address:".spaces($msg_indent-strlen($msg_address)).$_REQUEST['adresse'];
if ($_REQUEST['ort']) $message.="\n$msg_city:".spaces($msg_indent-strlen($msg_city)).$_REQUEST['ort'];
if ($_REQUEST['fon']) $message.="\n$msg_phone:".spaces($msg_indent-strlen($msg_phone)).$_REQUEST['fon'];
$message.="\n$msg_email:".spaces($msg_indent-strlen($msg_email))."mailto:".$_REQUEST['email'];
/* eliminazione risposta come
$message.="\n\n".spaces(strlen("$msg_answerby ".$_REQUEST['kontakt'])+1, "=");
$message.="\n$msg_answerby ".$_REQUEST['kontakt']."!\n";
$message.=spaces(strlen("$msg_answerby ".$_REQUEST['kontakt'])+1, "="); */
$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 "<table border='0' cellpadding='1' cellspacing='0' class='codform'>\n";
echo "<tr><td> </td>\n";
echo "</td></tr>\n";
echo "<tr><td width='150' class='$class_txt'>$msg_name*</td>\n";
echo "<td height='30'><input name='name' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['name']."'>\n";
echo "</td></tr>\n";
echo "<tr><td width='150' class='$class_txt'>$msg_surname*</td>\n";
echo "<td height='30'><input name='surname' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['surname']."'>\n";
echo "</td></tr>\n";
echo "<td height='30'> </td></tr>\n";
echo "<tr><td width='150' class='$class_txt'>$msg_company</td>\n";
echo "<td height='30'><input name='firma' id='firma' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['firma']."'>\n";
echo "<td height='30'> </td></tr>\n";
echo "<tr><td width='150' class='$class_txt'>$msg_sectore</td>\n";
echo "<td height='30'><input name='sectore' id='sectore' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['sectore']."'>\n";
echo "<tr><td width='150' class='$class_txt'>$msg_address</td>\n";
echo "<td height='30'><input name='adresse' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['adresse']."'>\n";
echo "</td></tr>\n";
echo "<tr><td width='150' class='$class_txt'>$msg_city</td>\n";
echo "<td height='30'><input name='ort' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['ort']."'>\n";
echo "</td></tr>\n";
echo "<tr><td width='150' class='$class_txt'>$msg_phone*</td>\n";
echo "<td height='30'><input name='fon' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['fon']."'>\n";
echo "</td></tr>\n";
echo "<tr><td width='150' class='$class_txt'>$msg_email*</td>\n";
echo "<td height='30'><input name='email' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['email']."'>\n";
echo "</td></tr>\n";
/*echo "<tr><td width='150' class='$class_txt'>$msg_answerby*</td>\n";
echo "<td height='30' class='$class_txt'><input name='kontakt' type='radio' value='$txt_email' checked> $txt_email \n";
echo "<input name='kontakt' type='radio' value='$txt_phone'> $txt_phone \n";
echo "<input name='kontakt' type='radio' value='$txt_post'> $txt_post\n";
echo "</td></tr>\n"; */
echo "<tr><td width='150' class='$class_txt'>$msg_request*</td>\n";
echo "<td height='30'><textarea name='message' cols='45'style='$style_inputfield' rows='10' class='$class_inputfield'>".$_REQUEST['message']."</textarea></td></tr>\n";
echo "<tr><td width='150' > </td>\n";
echo "<td height='30' class='pry2'>* $txt_mandatory</td></tr>\n";
echo "<tr><td width='150' class='$class_txt'></td>\n";
echo "<td height='30' class='pry'>
Informativa ai sensi dell’Art.13 D.lgs. 196/2003 sulla tutela dei dati personali (privacy)
Per accedere ad alcune aree del sito le chiederemo di fornirci alcune informazioni personali.
A questo proposito la informiamo che i suoi dati personali saranno da noi trattati manualmente e con mezzi informatici per:\n
a) dar seguito alla sua richiesta e tenerla informata in merito a nuovi servizi; \n
b) comunicazioni di marketing, attività promozionale e invio di materiale informativo. I suoi dati non saranno comunicati a terzi soggetti. I suoi dati non saranno diffusi.
Le ricordiamo che per far valere i suoi diritti previsti dall'articolo 7 del D.L. 30/6/2003 n.196 può rivolgersi al Titolare del Trattamento scrivendo a M.G.B. Magazzini Generali della Brianza Spa
</td></tr>\n";
echo "<tr><td width='150'> </td>\n";
echo "<td height='30' class'pry'><input name='consenso' type='radio' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['consenso']."'>\n";
echo "</td></tr>\n";
/*echo "<td height='30' class'pry'><input name='Acconsento' type='radio' value='Acconsento'>Do il consenso
\n";*/
echo "<tr><td width='150'> </td>\n";
echo "<td height='30' align='center'><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></table>\n";
echo "</form>\n";
}
/*
######################### END Contact Form ##########################
################################################## ###################
*/
?>
Grazie