Yes, I use javascript to check emails. There's a way to do it with preg_match in PHP, but I haven't been able to make it work. I use the following javascript:
Code:
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
function checkmail(e){
var returnval=emailfilter.test(e.value)
if (returnval==false){
alert("Please enter a valid email address.")
e.select()
}
return returnval}
Then, in the form, you add an onclick event to the submit button:
Code:
<input type="submit" value="Send" onclick="return checkmail(this.form.email)" />
Now, I've messed with some different solutions to the carrying back the info question. I tried adding those to the url along with the error message back to the contact page. However, especially with textarea's, that's a lot of info to be sending over the url. The best way would be to create a session. Add a session_start(); at the very top of the page and do something like this:
PHP Code:
if($name != "" & $email != "") {
$_SESSION['name'] = '';
$_SESSION['email'] = '';
// REST OF YOUR CODE HERE
}
else{
if($name == ''){$_SESSION['name'] = '';}
else{$_SESSION['name'] = $name;}
if($email == ''){$_SESSION['email'] = '';}
else{$_SESSION['email'] = $email;}
// REST OF YOUR CODE HERE
}
Then, in contact.php, get those session variables at the top of the page:
PHP Code:
session_start();
if(@$_SESSION['name']){$sname = $_SESSION['name'];}
else{$sname = '';}
if(@$_SESSION['email']){$semail = $_SESSION['email'];}
else{$semail = '';}
Then, put them in the form:
HTML Code:
<form action="formSender.php" method="post">
<h3>Contact Form</h3>
<label for="name" id="firstLabel">Name:</label>
<input type="text" name="name" value="<?=$sname?>" /><br />
<label for="email">Email:</label>
<input type="text" name="email" value="<?=$semail?>" /><br />
<input type="submit" value="Send" />
</form>
I didn't test this, but it should work.
Bookmarks