![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 172 Pomógł: 0 Dołączył: 11.06.2014 Ostrzeżenie: (0%) ![]() ![]() |
Przeczytałem wiele tematów i probowałem tych sposobów by to zabezpieczyć za pomocą header kompletnie tego nie mogłem wykonać, kolejną próbą było za pomocą randu i sesji niestety nic nie pomaga. Wyśle tutaj kod formularza, pisze od podstaw i pewnie kod nie jest najpiekniejszy, ale od czegos nauka musi się zacząć.
Plik główny formularza: Kod <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Dokument bez tytułu</title> <link rel="stylesheet" type="text/css" href="form-style.css" /> <script src="scrypt.js"></script> <script src="http://code.jquery.com/jquery-1.9.0.js"></script> </head> <body> <div id="container"> <h1>Contact Us</h1> <div id="done"></div> <?php if(isset($_POST['submit'])) { if($_POST['js']!='true'){ // jeśli nie (ukryte pole będzie różne od true) echo'<div id="php_error">Please turn on javascript in your browser and refresh website</div>'; } else{ include 'mail.php'; } } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="contactform" onsubmit="return validateForm(this);"> <fieldset> <input type="hidden" name="js"> <input id="clear0" class="clearable" type="text" placeholder="Subject" name="subject" value=""> <div class="error" id="subject"> </div> <input id="clear1" class="clearable" type="text" placeholder="First name" name="f_name" value=""> <div pow="pow" class="error" id="f_name"> </div> <input id="clear2" class="clearable" type="text" placeholder="Last name" name="l_name" value=""> <div class="error" id="l_name"> </div> <input id="clear3" class="clearable" type="text" placeholder="E-mail" name="email" value=""> <div class="error" id="email"> </div> <textarea id="clear4" class="clearable" rows="5" columns="10" name="contact_body" value=""></textarea> <div class="error" id="contact_body"> </div> <br/><input class="button" type="submit" name="submit" value="Submit"> <input class="button" type="button" name="B2" value="Clear" onclick="clearing2()" > </fieldset> </form> </div> </body> </html> Plik js Kod function ValidateEmail(address) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if(reg.test(address) == false) { return false; } else { return true; } } function validateForm(AForm) { AForm.js.value='true'; var tekst=''; if (AForm.subject.value==""){ tekst=tekst+"Nieprawid³owy format\n"; document.getElementById('subject').innerHTML="*Subject empty"; document.getElementById('subject').className="red_error"; } else { document.getElementById('subject').innerHTML="*Correct"; document.getElementById('subject').className="green_error"; } if (AForm.f_name.value==""){ tekst=tekst+"Nieprawid³owy format\n"; document.getElementById('f_name').innerHTML="*First name empty"; document.getElementById('f_name').className="red_error"; } else { document.getElementById('f_name').innerHTML="*Correct"; document.getElementById('f_name').className="green_error"; } if (AForm.l_name.value==""){ tekst=tekst+"Nieprawid³owy format\n"; document.getElementById('l_name').innerHTML="*Last name empty"; document.getElementById('l_name').className="red_error"; } else { document.getElementById('l_name').innerHTML="*Correct"; document.getElementById('l_name').className="green_error"; } if (AForm.contact_body.value==""){ tekst=tekst+"Nieprawid³owy format\n"; document.getElementById('contact_body').innerHTML="*text empty"; document.getElementById('contact_body').className="red_error"; } else { document.getElementById('contact_body').innerHTML="*Correct"; document.getElementById('contact_body').className="green_error"; } if (!ValidateEmail(AForm.email.value)) { tekst=tekst+"Nieprawid³owy format"; document.getElementById('email').innerHTML="*Incorrent e-mail"; document.getElementById('email').className="red_error"; } else { document.getElementById('email').innerHTML="*Correct"; document.getElementById('email').className="green_error"; } if (tekst!="") { // alert ("WYSTAPI£Y NASTÊPUJCE B£ÊDY\n"+tekst); return false; } else { test_masage=1; return true; } } function clearing1(){ document.getElementById('clear1').value=""; document.getElementById('clear2').value=""; document.getElementById('clear3').value=""; document.getElementById('clear4').value=""; } function clearing2(){ for(i=0; i<5; i++){ document.getElementsByClassName('clearable')[i].value=""; //document.getElementsByClassName('red_error')[i].innerHTML=""; //document.getElementsByClassName('green_error')[i].innerHTML=""; } document.getElementById('f_name').innerHTML=""; document.getElementById('l_name').innerHTML=""; document.getElementById('email').innerHTML=""; document.getElementById('contact_body').innerHTML=""; document.getElementById('subject').innerHTML=""; } plik mail.php Kod <?php $to = 'okruszek90@gmail.com'; @$email = $_POST['email']; @$f_name = $_POST['f_name']; @$l_name = $_POST['l_name']; $to = 'mail@mail.pl'; $test = $email; @$subject = $_POST['subject']; @$contact_body= $_POST['contact_body']; // message $message = '<html><body>'; $message .= '<table width="100%" border="0" cellpadding="10">'; $message .= "<tr style='background: #eee;'><td width='50'><strong>Subject:</strong> </td><td>" . strip_tags($_POST['subject']) . "</td></tr>"; $message .= "<tr style='background: #f9f9f9;'><td ><strong>Name:</strong> </td><td>" . strip_tags($_POST['f_name']) ." ".strip_tags($_POST['l_name']). "</td></tr>"; $message .= "<tr style='background: #f9f9f9;'><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['email']) . "</td></tr>"; $message .= "<tr style='background: #fafafa;'><td><strong>Massage:</strong> </td><td>" . htmlentities($_POST['contact_body']) . "</td></tr>"; $message .= "</table>"; $message .= "</body></html>"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers = "From: " . strip_tags($_POST['email']) . "\r\n"; $headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n"; //$headers .= "CC: susan@example.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; // Mail it mail($to, $subject, $message, $headers); print "<script type='text/javascript'><!--\n"; //print "document.getElementById('done').style.display = 'block'"; print "document.getElementById('done').innerHTML='Message has been sent';\n"; print "setTimeout(function(){document.getElementById('done').style.display = 'none'}, 4000)"; // Zakończenie skryptu print "//--></script>\n"; ?> Podsumowując problem jest taki, że podczas wpisania wiadomości i wysłaniu można odświezac strone i wysylac wciaz wiadomosci na maila, nie mowiąc o klikaniu submit wielokrotnie co sprawia wyslanie wielu wiadomości. dziekuję z góry za pomoc |
|
|
![]()
Post
#2
|
|
![]() Grupa: Moderatorzy Postów: 36 557 Pomógł: 6315 Dołączył: 27.12.2004 ![]() |
http://forum.php.pl/index.php?showtopic=44...t=0&start=0
sposob z header to jeden z lepszych. Jaki miales z nim problem? Zakladam, ze wiesz, iz header nie mozna wykonac, gdy sie juz cos wyslalo do przelgadarki... a patrzac na Twoj zly kod, tak wlasnie zapewne miales. Albo poczytaj o buforowaniu (funkcje z rodziny ob_ )albo popraw kod na poprawny: najpierw logika, potem wyswietlanie. Wowczas header bedzie dzialal bez problemu -------------------- "Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista "Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer |
|
|
![]()
Post
#3
|
|
Grupa: Zarejestrowani Postów: 172 Pomógł: 0 Dołączył: 11.06.2014 Ostrzeżenie: (0%) ![]() ![]() |
No tak racja z tym header, moze musze odpocząć od tego bo sam sobie pewnie za duzo mieszam w kodzie i mam problem z tym. :/
Tak aby zmodyfikowaćto na header nie mam kompletnie zielonego pojecia, moze latwiej mi pojdzie z sesjami, ale z tym poki co tez jestem w lesie Ten post edytował atom90 11.06.2014, 11:53:33 |
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 19.07.2025 - 17:09 |