Question:
How to handle javascript on click to php and email validation.?
Steven
2013-07-02 09:24:07 UTC
Hello, I'm making a contact form and I have two problems. The first is how do I be sure an email is entered in the email field, I can check to make sure something is there, but I don't know how to make sure it's an email.

The second one is I want a javascript onclick event to post the variables to my contact form page. So, if all the fields aren't filled out it will read an error during the onlclick() function and remain on the same page. But, if it is all filled out then it allows the contact.php page to take the post variables. Is there any way to do this?
Three answers:
?
2013-07-05 14:25:15 UTC
Firstly, the only way you can tell if an email is valid is by sending a mail to that address and asking the recipient to reply. Are you going to do that? If not, is there any point in testing if the email address entered is the correct format? You might as well just test that it's not empty.



Secondly you MUST validate your data on the server side. Client side javascript validation is just to help out the user, so they get feedback about issues as soon as possible. But it can easily be turned off or bypassed, if your not checking your input data on the server anyone can post garbage data directly into your DB.
?
2013-07-02 10:00:05 UTC
Try, then download "form to email" script from http://web2coders.com (php tab). It has an email validation script BEFORE sending the form.

Note: contrary to popular belief, it i NOT possible to find out if the email address EXISTS, unless you ask the recipient to REPLY to that email to confirm its existence.

The php function "mail()" only returns "email has been accepted by the mail server": it does NOT mean that it has been sent, nor that it has been RECIEVED at the other end...

(It would be a great asset for spammers if there were a way to confirm an email existence...)
anonymous
2013-07-03 06:13:14 UTC
hello,



To read an input form value in javascript:

---------------------------------------------------------

document. getElementById ("ID-NAME"). value;



Example:

-----------------



inside javascript tags:

-------------------------------

function valid(){

var email=document.getElementById ("email"). value;

n=email.search("@");

n2=email.search(".co");

if((n>0)&&(n2>0)){

}else

alert("please type a valid email");

}





the html:

-------------

Email:




submit





search in char :javascript:

------------------------------------

http://www.w3schools.com/jsref/jsref_search.asp



get input form:

-----------------------------------



http://stackoverflow.com/questions/11563638/javascript-get-input-text-value



*same method goes for the rest of the form..





a different method in PHP, is in the recieving page :



example:



$user=$_POST["USERNAME"];

if (!$user) {

echo "please type your username..";

include "yourform.php";

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...