fantomel Posted September 24, 2009 Share Posted September 24, 2009 Hello i've build a contact form and ajaxed a little bit without ajax(using it to submit data) works perfect but now since i've implemented ajax in it it says that the email address isn't correct can someone take a look over the php code on the line <php if (!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$", $email)) { $verificare = 1; echo '<br>Adresa de e-mail este incorecta.'; } ?> and tell me if the regex is correct? after submit the data using ajax it keeps echo the error Adresa de e-mail este incorecta in translation the e-mail is not valid. entire code: <?php // se creaza o functie care afişeaza formularul function afisare_formular($stare=1) { /* daca valoarea variabilei $stare este 1 atunci se afiseaza formularul normal si se seteaza valorile din formular la 0 */ if ($stare == 1) { $nume = ''; $email = ''; $telefon = ''; $mesaj = ''; } /* daca valoarea variabilei $stare este diferita de 1 atunci se preiau mai intai datele trimise anterior prin POST din formular si se afiseaza formularul din nou dar cu valorile primite. */ else { $nume = $_POST['nume']; $email = $_POST['email']; $telefon = $_POST['telefon']; $mesaj = $_POST['mesaj']; } // se genereaza variabila cu tabelul care contine formularul $formular = ' <div class="contact_form"> <fieldset> <form name="contact" id="contact" method="post" action=""> <label for"Nume">Name:</label><br /> <input name="nume" type="text" id="nume" value="'.$nume.'" maxlength="50"><br /> <label for="Email">E-mail:</label><br /> <input name="email" type="text" id="email" value="'.$email.'" maxlength="50"><br /> <label for="Phone">Phone:</label><br /> <input name="telefon" type="text" id="telefon" value="'.$telefon.'" maxlength="15"><br /> <label for="Message">Message:</label><br /> <textarea name="mesaj" cols="35" rows="3" wrap="virtual" id="mesaj">'.$mesaj.'</textarea><br /> <input type="submit" name="Submit" value="Trimite"><br /> </form> '. $nume . $email . $telefon . $mesaj .' <div class="success" style="display:none;">Client has been added.</div> </fieldset> </div>'; // se returneaza codul html pentru formularul care trebuie afisat return $formular; } /* daca a fost incarcata prima data aceasta pagina de catre vizitator se afiseaza formularul normal */ if (!isset($_POST['nume'])) { echo afisare_formular(1); } /* daca a fost deja apasat butonul te trimitere din formular se preiau datele trimise si se verifica daca sunt corecte */ else { // se preiau datele trimise $nume = $_POST['nume']; $email = $_POST['email']; $telefon = $_POST['telefon']; $mesaj = $_POST['mesaj']; // se verifica daca sunt corecte $verificare = 0; if (empty($nume)) { $verificare = 1; echo '<br>Nu a fost specificat Numele si prenumele.'; } if (strlen($nume) < 3) { $verificare = 1; echo '<br>Numele trebuie sa contina minim 3 caractere.'; } elseif (!eregi('[a-zA-Z ]{3}', $nume)) { $verificare = 1; echo '<br>Numele trebuie sa contina minim 3 caractere.'; } if (empty($email)) { $verificare = 1; echo '<br>Nu a fost introdusa adresa de e-mail'; } if (!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,4}$", $email)) { $verificare = 1; echo '<br>Adresa de e-mail este incorecta.'; } if (empty($telefon)) { $verificare = 1; echo '<br>Nu a fost specificat un numar de telefon. Scrieti (-) daca nu aveti telefon.'; } if (empty($mesaj)) { $verificare = 1; echo '<br>Nu a fost specificat mesajul pe care doriti sa il trimiteti.'; } /* daca in urma verificarilor de mai sus a aparut o eroare atunci variabila de verificare ar trebui sa aiba valoarea 1 si in acest caz se afiseaza din nou formularul cu campurile deja completate pentru corectare */ if ($verificare == 1) { echo afisare_formular(0); } /* daca in urma verificarilor de mai sus totul este ok se trimite mesajul pe e-mail */ else { // se stabilesc variabilele care se vor trimite prin mail $subiect = 'Mesaj de la '.$_SERVER['SERVER_NAME']; // aici scrieti adresa de e-mail unde doriti sa primiti mesajele $adresa = '[email protected]'; $continut = '<br>Nume si prenume: '.$nume.' <br>Adresa de e-mail: '.$email.' <br>Telefon: '.$telefon.' <br>Mesaj:<br><br>'.$mesaj.' <br>Mesajul a fost trimis la data de '.date('d-m-Y H:i', time()); $headere = "From: $nume <$email>\r\n". "Reply-To: $email\r\n". "MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-2\r\n"; "X-Mailer: PHP/" . phpversion();; // aici se incearca trimiterea mesajului pe mail if (@mail($adresa, $subiect, $continut, $headere)) { echo '<META HTTP-EQUIV = "Refresh" Content = "10; URL =index.php"> Mesajul a fost trimis cu succes. Asteptati pentru redirectare.'; } else { echo '<META HTTP-EQUIV = "Refresh" Content = "10; URL ='.$_SERVER['PHP_SELF'].'"> A aparut o eroare la serverul de mail, va rugam sa incercati din nou.<br> Asteptati pentru redirectare.'; } } } ?> Link to comment https://forums.phpfreaks.com/topic/175380-contact-form-a-little-lookout-over-it/ Share on other sites More sharing options...
gevans Posted September 24, 2009 Share Posted September 24, 2009 Can you show your javascript? And have you altered the post/get data at all. The email address characters may have changed to be more 'url friendly'. Link to comment https://forums.phpfreaks.com/topic/175380-contact-form-a-little-lookout-over-it/#findComment-924225 Share on other sites More sharing options...
fantomel Posted September 24, 2009 Author Share Posted September 24, 2009 Can you show your javascript? And have you altered the post/get data at all. The email address characters may have changed to be more 'url friendly'. here you go my entire javascript $(function() { $('.text1').load("public_html/themes/en/content/home.php"); $('#header li a').click(function() { var url_to_load; var custom_handler = function(){}; var toLoad = $(this).attr("href"); switch(toLoad) { case "#home" : url_to_load = "public_html/themes/en/content/home.php";break; case "#products" : url_to_load = "public_html/themes/en/content/pro.php";break; case "#buy" : url_to_load = "public_html/themes/en/content/buy.php";break; case "#waste" : url_to_load = "public_html/themes/en/content/waste.php";break; case "#credentials" : url_to_load = "public_html/themes/en/content/credentials.php";break; case "#gallery" : url_to_load = "public_html/themes/en/content/gallery.php"; custom_handler = function(){$('.photo a').lightBox();}; break; case "#howto" : url_to_load = "public_html/themes/en/content/howto.php";break; case "#quality" : url_to_load = "public_html/themes/en/content/quality.php";break; case "#contact" : url_to_load = "public_html/themes/en/content/contact.php"; custom_handler = function() { $("#contact").live('submit', function() { // we want to store the values from the form input box, then send via ajax below var nume = $('#nume').attr('value'); var telefon = $('#telefon').attr('value'); var email = $('#email').attr('value'); var mesaj = $('#mesaj').attr('value'); console.log("$.ajax"); $.ajax({ type: "POST", url: "public_html/themes/en/content/contact.php", data: "nume="+ nume +" & telefon="+ telefon +" & email="+ email +" & mesaj="+ mesaj, success: function(){ $('form#contact').hide(); $('div.success').fadeIn(); } // end of success function }); // end of ajax return false; }); // end of submit function }; // end of custom handler function break; } // end of switch $(".text1").hide(); $("#content").slideDown(400); $(".text1").load(url_to_load,custom_handler); $(".text1").fadeIn(2000); }); }); Link to comment https://forums.phpfreaks.com/topic/175380-contact-form-a-little-lookout-over-it/#findComment-924240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.