Messaggio popup da contact form
-
Ciao a tutti, ho un form in php e vorrei che all'invio del modulo invece che restituirmi un messaggio in un'altra pagina tramite il comando echo, lo script mi restituisse un avviso popup con un solo pulsante di OK.
Come faccio? potete aiutarmi? Ecco il codice:
[FONT=Courier New]<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />. [/FONT] [COLOR=#0000bb][FONT=Courier New]<?php [/FONT][/COLOR] [FONT=Courier New][COLOR=#ff8000]// campi obbligatori [/COLOR][/FONT] [FONT=Courier New][COLOR=#007700]if (([/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'name'[/COLOR][COLOR=#007700]]) != [/COLOR][COLOR=#dd0000]""[/COLOR][COLOR=#007700]) && ([/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'surname'[/COLOR][COLOR=#007700]]) != [/COLOR][COLOR=#dd0000]""[/COLOR][COLOR=#007700]) && ([/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'email'[/COLOR][COLOR=#007700]]) != [/COLOR][COLOR=#dd0000]""[/COLOR][COLOR=#007700]) && ([/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'tel'[/COLOR][COLOR=#007700]]) != [/COLOR][COLOR=#dd0000]""[/COLOR][COLOR=#007700]) && ([/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'message'[/COLOR][COLOR=#007700]]) != [/COLOR][COLOR=#dd0000]""[/COLOR][/FONT][COLOR=#007700][FONT=Courier New])) { [/FONT][/COLOR] [FONT=Courier New][COLOR=#ff8000]// destinatario dell'e-mail [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$to [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]" \n [COLOR=#000080]indirizzo email destinatario[/COLOR] "[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]; [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$headers [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"From: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]'email'[/COLOR][COLOR=#007700]] . [/COLOR][COLOR=#dd0000]"\n"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]; [/FONT][/COLOR] [FONT=Courier New][COLOR=#ff8000]// oggetto dell' e-mail [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$subject [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"Contatto dal sito"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]; [/FONT][/COLOR] [FONT=Courier New][COLOR=#ff8000]// corpo messaggio [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$body [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#dd0000]"Hai ricevuto un messaggio dal sito con le seguenti informazioni:\n\n"[/COLOR][/FONT][FONT=Courier New][COLOR=#007700]; [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$body [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"Nome: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]stripslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"name"[/COLOR][COLOR=#007700]])) . [/COLOR][COLOR=#dd0000]"\n"[/COLOR][COLOR=#007700]; [/COLOR][/FONT][FONT=Courier New][COLOR=#ff8000]//nome del mittente [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$body [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"Cognome: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]stripslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"surname"[/COLOR][COLOR=#007700]])) . [/COLOR][COLOR=#dd0000]"\n"[/COLOR][COLOR=#007700]; [/COLOR][/FONT][FONT=Courier New][COLOR=#ff8000]//cognome del mittente [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$body [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"E-mail: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]stripslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"email"[/COLOR][COLOR=#007700]])) . [/COLOR][COLOR=#dd0000]"\n"[/COLOR][COLOR=#007700]; [/COLOR][/FONT][FONT=Courier New][COLOR=#ff8000]//indirizzo e-mail del mittente [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$body [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"Telefono: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]stripslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"tel"[/COLOR][COLOR=#007700]])) . [/COLOR][COLOR=#dd0000]"\n"[/COLOR][COLOR=#007700]; [/COLOR][/FONT][FONT=Courier New][COLOR=#ff8000]//numero del mittente [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$body [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"Sito web: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]stripslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"website"[/COLOR][COLOR=#007700]])) . [/COLOR][COLOR=#dd0000]"\n"[/COLOR][COLOR=#007700]; [/COLOR][/FONT][FONT=Courier New][COLOR=#ff8000]//sito del mittente [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]$body [/COLOR][COLOR=#007700].= [/COLOR][COLOR=#dd0000]"Messaggio: " [/COLOR][COLOR=#007700]. [/COLOR][COLOR=#0000bb]trim[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]stripslashes[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$_POST[/COLOR][COLOR=#007700][[/COLOR][COLOR=#dd0000]"message"[/COLOR][COLOR=#007700]])) . [/COLOR][COLOR=#dd0000]"\n"[/COLOR][COLOR=#007700]; [/COLOR][/FONT][FONT=Courier New][COLOR=#ff8000]//contenuto del messaggio [/COLOR][/FONT] [FONT=Courier New][COLOR=#ff8000]// invio mail [/COLOR][/FONT] [FONT=Courier New][COLOR=#0000bb]mail[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000bb]$to[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$subject[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$body[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000bb]$headers[/COLOR][COLOR=#007700]); [/COLOR][/FONT][FONT=Courier New][COLOR=#ff8000]// SE L'INOLTRO E' ANDATO A BUON FINE... [/COLOR][/FONT] [FONT=Courier New][COLOR=#007700]echo [/COLOR][COLOR=#dd0000]"E-mail inviata correttamente. Grazie per avermi contattata!"[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]; [/FONT][/COLOR] [FONT=Courier New][COLOR=#007700]} else {[/COLOR][/FONT][FONT=Courier New][COLOR=#ff8000]// altrimenti [/COLOR][/FONT] [FONT=Courier New][COLOR=#007700]echo [/COLOR][COLOR=#dd0000]"E' necessario compilare tutti i campi prima di inviare."[/COLOR][/FONT][COLOR=#007700][FONT=Courier New]; [/FONT][/COLOR] [FONT=Courier New][COLOR=#007700]} [/COLOR][/FONT] [COLOR=#0000bb][FONT=Courier New]?> [/FONT][/COLOR] -
-
Quindi un box alert che effettivamete, mostrando un resoconto delle informazioni, ti dica se vuoi continuare a inviare le informazioni o no?
-
-
Il controllo degli errori io lo farei a priori, prima di inviare il form, perchè gia prima sai se il form è compilato correttamente.
-
Non sono capace purtroppo, infatti ho inserito gli asterischi che indicano quale dei campi è obbligatorio.. mi accontento di un form semplice come quello che ho fatto ma invece di darmi il messaggio in una pagina bianca, vorrei che me lo desse in un alert box. tutto qui..
-
Prova a vedere se ti va bene questo codice.
C'è un pò di tutto, un controllo Javascript prima dell'invio dati, e del php che ti dice se va tutto bene.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Test</title> <style type="text/css"> html,body { margin:0px; padding:0px; background:#AAD4FF; } .sposta { margin:10px; } </style> <script type="text/javascript"> function controlla() { var cognome=document.getElementById("cognome"); var valoreCognome=cognome.value; if(valoreCognome=="") { alert("Il cognome è obbligatorio, compilarlo prima di proseguire!"); } else { document.myform.submit(); } } </script> </head> <body> <?php $valoreNome=$_POST['nome']; $valoreCognome=$_POST['cognome']; if($valoreNome==""&&$valoreCognome=="") { ?> <form name="myform" id="myform" action="index.php" method="post"> <div><input class="sposta" id="nome" name="nome" /><span class="sposta">Nome</span></div> <div><input class="sposta" id="cognome" name="cognome" /><span class="sposta">Cognome *</span></div> <div><input class="sposta" type="button" value="INVIO" onclick="controlla()"/></div> </form> <?php } else { echo "Form inviato con successo!"; } ?> </body> </html> -
Non mi sono spiegato bene.. a me serve utilizzare il seguente codice ma con la dovuta modifica per adattarlo alla mia esigenza.
Ti incollo prima il codice html e poi il php:<form action="mail.php" method="post" id="modulo"> <div class="form_row"> <label>Nome:</label> <input name="name" type="text" id="name" class="contact_input"/> </div> <div class="form_row"> <label>Cognome:</label> <input name="surname" type="text" id="surname" class="contact_input"/> </div> <div class="form_row"> <label>E-mail:</label> <input name="email" type="text" id="email" class="contact_input"/> </div> <div class="form_row"> <label>Telefono:</label> <input name="tel" type="text" id="tel" class="contact_input"/> </div> <div class="form_row"> <label>Messaggio:</label> <textarea name="message" cols="30" rows="5" id="message" class="contact_textarea"></textarea> </div> <div class="form_row"> <input type="submit" name="submit" id="submit" class="contact_submit" value="Invia" /> </div> </form><?php // campi obbligatori if ((trim($_POST['name']) != "") && (trim($_POST['surname']) != "") && (trim($_POST['email']) != "") && (trim($_POST['tel']) != "") && (trim($_POST['message']) != "")) { // destinatario dell'e-mail $to = " \n indirizzo email destinatario "; $headers = "From: " . $_POST['email'] . "\n"; // oggetto dell' e-mail $subject = "Contatto dal sito"; // corpo messaggio $body = "Hai ricevuto un messaggio dal sito con le seguenti informazioni:\n\n"; $body .= "Nome: " . trim(stripslashes($_POST["name"])) . "\n"; //nome del mittente $body .= "Cognome: " . trim(stripslashes($_POST["surname"])) . "\n"; //cognome del mittente $body .= "E-mail: " . trim(stripslashes($_POST["email"])) . "\n"; //indirizzo e-mail del mittente $body .= "Telefono: " . trim(stripslashes($_POST["tel"])) . "\n"; //numero del mittente $body .= "Sito web: " . trim(stripslashes($_POST["website"])) . "\n"; //sito del mittente $body .= "Messaggio: " . trim(stripslashes($_POST["message"])) . "\n"; //contenuto del messaggio // invio mail mail($to, $subject, $body, $headers); // SE L'INOLTRO E' ANDATO A BUON FINE... echo "E-mail inviata correttamente. Grazie per avermi contattata!"; } else {// altrimenti echo "E' necessario compilare tutti i campi prima di inviare."; } ?>
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi