Why message written in contact form doesn't deliver to email? - php

I made a simple contact form for my website. At the moment, after sending the message, it shows "The message is sent successfully" but doesn't really send. It can't deliver to the stated email address.
Why so? Is there anything wrong in my code? Also
jQuery(document).ready(function($){
the above function isn't working I guess.
My PHP file:
<div id="contact">
<!--
Contact form begins
-->
<div class="container">
<?php
$hasError=false;
$sent=false;
if(isset($_POST['submitform'])){
$name=trim(htmlspecialchars($_POST['name'],ENT_QUOTES));
$email=trim($_POST['email']);
$message=trim(htmlspecialchars($_POST['message'], ENT_QUOTES));
$fieldsArray=array(
'name'=>$name,
'email'=>$email,
'message'=>$message
);
$errorArray=array();
foreach($fieldsArray as $key=>$val){
switch($key){
case 'name':
case 'message':
if(empty($val)){
$hasError=true;
$errorArray[$_key]=ucfirst($key)."field was left empty.";
}
break;
case 'email':
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
$hasError=true;
$errorArray[$key]="Invalid email address entered";
}else{
$email=filter_var($email, FILTER_SANITIZE_EMAIL);
}
break;
}
}
if(hasError!==true){
$to="jabirfatah91#yahoo.com";
$subject="Message from your website";
$msgcontents="Name: $name<br>Email:$email<br>Message: $message";
$headers.="MIME-version:1.0\r\n";
$headers.="From:$name<$email>\r\n";
$mailsent=mail($to, $subject, $messagecontents, $headers);
if($mailsent){
$sent=true;
unset($name);
unset($email);
unset($message);
}
}
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Conatct form</title>
<link rel="stylesheet" type="text/css" href="contactformdesign.css">
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($){
$("#contactform").validate({
rules:{
name:{
required:true,
minlength:2
},
email:{
required:true,
email:true
},
message:{
required:true,
minlength:50
}
},
message:{
name:{
required:"Please type your name",
minlength:"Your name seems a bit short"
},
email:{
required:"Please enter your email address",
email:"Please enter a valid email address"
},
message:{
required:"Please type your message",
minlength:"Your message seems a bit short. Please enter minimum 50 character"
}
}
});
});
</script>
</head>
<body>
<div class="container">
<h1>Contact form</h2>
<form id="contactform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" novalidate>
<?php
if($sent===true){
echo "<h2 class='success'>Thanks, your message has been sent successfully</h2>";
}elseif($hasError===true){
echo '<ul class="errorlist">';
foreach($errorArray as $key =>$val){
echo "<li>".ucfirst($key)."field error-$val</li>";
}
echo '</ul>';
}
?>
<input type="text" name="name" value="<?php echo (isset($name)? $name: ""); ?>" placeholder="Your name">
<input type="email" name="email" value="<?php echo (isset ($email)? $email:"");?>" placeholder="Your E-mail">
<textarea name="message" placeholder="Your Message"><?php echo (isset($message)? $message: ""); ?></textarea>
<input type="submit" name="submitform" value="Send">
</form>
</div>
</body>
</html>
</div>
<!--
Contact form ends.
-->

If you're trying to send the mail directly FROM the email entered by the user, some mail receivers will block mail from certain addresses and it will never get through, despite your SCRIPT thinking it sent successfully.
This was a problem I personally had with Wordpress's 'Contact Form 7', and found some other references to on-line.
It was solved by NOT using the email entered in the form, but using the site's contact email - 'contact#yoursite.com', and just referencing the email address in the body of the email.
As for jQuery's document ready -
make sure jQuery is loaded on the page
Check out the docs again - http://api.jquery.com/ready/
Do you really need that syntax? Is something else using '$' on your page? If not, it's much simpler to use $(function(){ //your code });
open a new question if you really can't solve it using the docs

Related

Submitting Form Details to Mail via PHP

I am fairly new to PHP. So, may be it is a very silly mistake I am doing. I have to send the form details to mail id. I browsed through The Internet and get the various link about the same. I got the files and changed them according to my needs. But I am facing error 500 and I am not able to understand what is the cause behind this.
My HTML is-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>app</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width; initial-scale=1.0">
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="app.js"></script>
</head>
<body>
<div id="form-messages" class="success">
</div>
<form id="ajax-contact" method="post" action="mailer.php">
<div class="field">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div class="field">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="field">
<label for="message">Message:</label>
<textarea id="message" name="message" required> </textarea>
</div>
<div class="field">
<button type="submit">Send</button>
</div>
</form>
</body>
</html>
My mailer.php is
<?php
// Only process POST reqeusts.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Set the recipient email address.
// FIXME: Update this to your desired email address.
$recipient = "hello#example.com";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
echo "Thank You! Your message has been sent.";
} else {
// Set a 500 (internal server error) response code.
http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
} else {
// Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
?>
My app.js file is
$(function() {
// Get the form.
var form = $('#ajax-contact');
// Get the messages div.
var formMessages = $('#form-messages');
// Set up an event listener for the contact form.
$(form).submit(function(e) {
// Stop the browser from submitting the form.
e.preventDefault();
// Serialize the form data.
var formData = $(form).serialize();
// Submit the form using AJAX.
$.ajax({
type: 'POST',
url: $(form).attr('action'),
data: formData
}).done(function(response) {
// Make sure that the formMessages div has the 'success' class.
$(formMessages).removeClass('error');
$(formMessages).addClass('success');
// Set the message text.
$(formMessages).text(response);
// Clear the form.
$('#name').val('');
$('#email').val('');
$('#message').val('');
}).fail(function(data) {
// Make sure that the formMessages div has the 'error' class.
$(formMessages).removeClass('success');
$(formMessages).addClass('error');
// Set the message text.
if (data.responseText !== '') {
$(formMessages).text(data.responseText);
} else {
$(formMessages).text('Oops! An error occured and your message could not be sent.');
}
});
});
});
Can anyone please look into this issue. I have not much and I am not able to solve this issue. Please help me?
It is giving 500 error because you have code
http_response_code(500);
in else condition and which is getting called may be because php mail() functionality is not available on localhost (or on server which you are using).
Alternatively you can use any SMTP class to send emails. Also, You can configure your gmail id with SMTP class.
may be you didn't set mail credentials see here how can you do this.
php manual

Send php mail using html webform

I have set up a page that is still in construction and i'm building a webform for users to contact me.
When i fill the webform and hit the "send" button, message gets send succesfully and i receieve it on my mail...but when i hit the "send" button, i get re-directed off page, saying it was sent successfully.
How can i prompt user that the message was sent successfully, without getting redirected of page, and get the message in same window?
This is my HTML code
<form action="assets/php/contactUs.php" id="contact" class="form" role="form" method="post">
<div class="row">
<div class="col-xs-6 col-md-6 form-group">
<input class="form-control" id="name" name="name" placeholder="Name" type="text" required />
</div>
<div class="col-xs-6 col-md-6 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="email" required />
</div>
</div>
<textarea class="form-control" id="message" name="message" placeholder="Message" rows="5"></textarea>
<div class="row">
<div class="col-xs-12 col-md-12">
<button class="btn btn btn-lg">Send Message</button>
</div>
</div>
</form>
And this is my contactUs.php code
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$message = <<<EMAIL
$message
From: $name
My email is: $email
EMAIL;
$to = "mymail#mymail.com";
$subject = "New Customer Enquiry";
mail($to, $subject, $message, "From: " . $email);
echo "Thank you, your message has been successfully sent!";
?>
AJAX
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$('.btn-lg').click(function(){
$.post( "assets/php/contactUs.php", $( "#contact" ).serialize(), function(msg){
alert(msg);
} );
});
});
</script>
This is a result of successfully sent message.
Please guys help me out! Thanks!
REDIRECT OPTION
$firstpageurl = 'http://example.com';
echo "Your message has been successfully sent!";
$header('Location: '.$firstpageurl);
Use Ajax as below.Change the submit type button to a normal button by removing the type attribute.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$('.btn-lg').click(function(event){
$.post( "config.php", $( "#contact" ).serialize(), function(msg){
alert(msg);
} );
event.preventDefault();
});
});
</script>
The action part of your form tag is "assets/php/contactUs.php"
<form action="assets/php/contactUs.php" id="contact" class="form" role="form" method="post">
That means that posting this form will bring you to that page. You can either code that page to send the email and redirect them back like this...
header('Location: '.$firstpageurl);
or put the php code into this first page and remove the entire action property. If you put the php on this page, you need to wrap your code in an if so that people can load the page before posting the form.
if (isset($_POST['email'])){
echo "Sent email";
[email send code here]
}
as for putting the message saying it's sent...that will only work with the second method. To do it without a full page load at all do it with ajax.
You want to use JQuery for that.
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
$("#contact").submit(function(){
var form_data=$("form").serialize();
$.post( "assets/php/contactUs.php",form_data, function( data ) {
alert(data);
});
event.preventDefault();
});
</script>
You can do it without using Javascript. Do the following:
Set the form to post to itself (e.g. if your form was on index.php, set action="index.php"
When the page loads, check $_POST to see if the form values were sent.
If the $_POST values are empty, display the form
If the $_POST values are set, do what you need to do with those values, then output your results into the page.
Here's a really simple example demonstrating what I mean.
<?php
$submitted = false;
if (isset($_POST["myinput"]) && $_POST["myinput"] != '') {
$submitted = true;
}
?>
<?php
if ($submitted == false) {
?>
<form action="index.php" method="post">
<input name="myinput"><input type="submit">
</form>
<?php } else { ?>
<h1>Form Submitted</h1>
<?php } ?>

PHP Form Troubles

I am using 000webhost for my website and they keep suspending my account because I am apparently sending more that 1000 emails. This happens about 30 seconds after submitting an email via my contact form. I am only receiving one email and all emails outbound from the form go to me, they arent in my spam either.
I just wanted an opinion on whether this form is actually looping and sending the message but im not getting them or this is 000webhost fault. I had a contact form since I made this website and its only causing issues now.
Heres the code for the contact form:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="CSS/primary.css"> <!--Address Using URL to prevent no styling when slash is typed-->
<link rel="shortcut icon" href="Images/tabIcon.ico">
<title>Harry Felton | Welcome</title>
</head>
<script language="php">
require_once'header.php';
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$('body').hide()
$("#notify").hide()
</script>
<script>
function toggleAbout(){
if ($("#center").hasClass("up")) {
$("#about").slideToggle(500);
setTimeout(function() {
$("#center").css({
msTransform: 'translateY(10px)',
webkitTransform: 'translateY(10px)',
transform: 'translateY(10px)',
})
}, 500);
} else {
$("#center").css({
msTransform: 'translateY(-75px)',
webkitTransform: 'translateY(-75px)',
transform: 'translateY(-75px)',
})
setTimeout(function() {
$("#about").slideToggle(500);
}, 1000);
}
$($("#center").toggleClass("up"))
};
</script>
<body onunload="" class="pg-index">
<div class="overwrap">
<div id="center">
<h1 id="title1">Welcome</h1>
<h2 id="title2">Harry Felton</h2>
<h2 id="subTitle">Auckland | New Zealand</h2>
<br><br><br><br>
<div id="about" style="display: none;">
<p>Hi, My name is Harry and I am an amateur programmer, I just do it as a hobby until I can actually take it as a course, I have created many programs, and love doing it, I am also into ComputerCraft which is a mod for Minecraft that adds programmable computers.<br><br>This website domain was initially created around September 2014, It took about a week to create, It was awesome, As it was the first time I had ever used HTML, CSS or JavaScript. On the 20th November I chose to completely recreate the website, So I deleted all files, And now... Here we are.<br><br>My absolute favorite thing to do in this world is code, I enjoy making, distributing and using my programs, And the feedback is always awesome, If you feel like leaving feedback, then click HERE</p>
</div>
</div>
</div>
<script type="text/javascript" src="JavaScript/element.js"></script>
<script type="text/javascript" src="JavaScript/pageNav.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js"></script>
<div id="contactForm" class="hidden">
<title>Contact Us</title>
<div id="mainPageCont">
<?php error_reporting(0); ?>
<?php if(isset($_POST['Email'])): ?>
<?php
$to = 'harryfelton12#gmail.com';
$subject = 'ALERT! Website Form Submission';
$message = 'Users Name: '.strip_tags($_POST['Name'])."\n";
$message .= 'Users Email: '.strip_tags($_POST['Email'])."\n";
$message .= 'Submitted Message: '.strip_tags($_POST['Comment'])."\n";
$headers = 'From: noReply#harryfelton.com' . "\r\n" .
'Reply-To: '.strip_tags($_POST['Email']) . "\r\n";
?>
<?php if(mail($to, $subject, $message, $headers)): ?>
<script type="text/javascript">
console.log('Mail OK')
location.href="/"
</script>
<?php endif ?>
<?php else: ?>
<script>console.log('Loading Contact Script')</script>
<form method="post" id="comments_form">
<h2>Please Leave Some Feedback, It Helps!</h2>
<div class="row">
<div class="label">
Your Name
</div>
<!--.label end-->
<div class="input">
<input type="text" id="fullname" class="detail" name="Name"
value="<?php echo isset($_POST['Name'])? $_POST['Name'] : ''; ?>" placeholder="e.g John Doe"/>
</div>
<!--.input end-->
<div class="context">
<span>We want to know who we are talking too</span>
</div>
<!--end .context-->
</div>
<!--.row end-->
<div class="row">
<div class="label">
Your Email
</div>
<!--.label end-->
<div class="input">
<input type="text" id="email" class="detail" name="Email" placeholder="e.g test#example.com" value="<?php echo isset($_POST['Email'])? $_POST['Email'] : ''; ?>" />
</div>
<!--.input end-->
<div class="context">
<span>We will send an email to this address containing a confirmation and any further replies</span>
</div>
<!--end .context-->
</div>
<!--.row end-->
<div class="row">
<div class="label">
Your Message
</div>
<!--.label end-->
<div class="input2">
<textarea id="Comment" name="Comment" class="mess"><?php echo isset($_POST['Comment'])? $_POST['Comment'] : ''; ?></textarea>
</div>
<!--.input end-->
</div>
<!--.row end-->
<div class="submit">
<input type="submit" id="submit" name="Submit" value="Send Message" />
</div>
</form>
<?php endif; ?>
<script>
function CheckVal() {
var SetMess = $('#option').val();
$('#feedback').html(SetMess);
if (SetMess !== '') {
$('#submit').prop('disabled', false);
}
else {
$('#submit').prop('disabled', true);
}
}
// As one types, check that the message is not empty
$('#option').keyup(function () {
CheckVal();
});
// As one clicks into the field, see if it has content
$('#option').click(function () {
CheckVal();
});
$(document).ready(function() {
// validate form
$("#comments_form").validate({
// This will allow you to extend the validator functions
invalidHandler:
function(form, validator) {
// $("#get_online").val("CHECK");
},
rules: {
// For every named input that you want to validate,
// you create a little set of prefs
Name: {
required: true,
},
Email: {
required: true,
email: true
},
Comment: { required: true },
},
messages: {
// Here are just the custom messages you can modify per field
Name: {
required: 'Please Enter Your Name',
},
Email: {
required: 'Please Enter An Email',
email: 'Email address not valid',
},
Comment: { required: 'Please Enter A Message'},
},
});
});
</script>
</div>
</div>
</div>
<script>
$(document).ready(function() {
fadeIn("body");
setTimeout(function() {
notification();
}, 500)
});
</script>
<script>changeWelcome("#title1");</script>
<div id="notify">Disabled JavaScript Is Now Supported, Contact Form Is Being Worked On Again!<a onclick="notification();" id="notifyClose">x</a></div>
<script>
function notification() {
isNotify = true
notifyID = "#notify"
if (isNotify) {
if ($(notifyID).hasClass("vis")) {
console.log("Notification Bar Enabled, Hiding: "+notifyID);
$(notifyID).slideUp(500);
} else {
$(notifyID).slideDown(500);
console.log("Notification Bar Enabled, Showing: "+notifyID);
}
$(notifyID).toggleClass("vis");
}
}
</script>
</body>
</html>
If you guys wanna visit the webiste then heres the link: http://www.harryfelton.host56.com/ Although it may be offline due to the account being suspended.
So... what do you think, is this loop sending 1000 emails? Ive been doing some console and alert testing and it never seems to send a message more than once, but I thought maybe the pause time had an effect.
I think if someone were to disable javascript in their browser, they could bypass your jQuery validation and send 1000 emails because you are not validating your Reply-To email server-side.
Try changing your server-side validation to something like:
$to = 'harryfelton12#gmail.com';
$subject = 'ALERT! Website Form Submission';
$message = 'Users Name: '.strip_tags($_POST['Name'])."\n";
$message .= 'Users Email: '.strip_tags($_POST['Email'])."\n";
$message .= 'Submitted Message: '.strip_tags($_POST['Comment'])."\n";
$headers = 'From: noReply#harryfelton.com' . "\r\n" .
'Reply-To: '.strip_tags($_POST['Email']) . "\r\n";
// User the filter_var() function to check that there is no manipulation
// of the $headers
if(filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)) {
if(mail($to, $subject, $message, $headers)) { ?>
<script type="text/javascript">
console.log('Mail OK')
location.href="/"
</script>
<?php }
} ?>
I don't see any loop and from what you have posted. aside from server-side validation, I don't see any reason why it should send 1000 emails.

What is wrong with my form via Ajax to PHP?

Been scouring this site and find many AJAX to PHP examples but following these I cannot figure why on earth my scripts are not working.
I have an HTML form with a button. You click the button it calls a Bootstrap modal window. You enter an email address click Submit.
It posts to a PHP file that will email me.
The reason I am implementing using AJAX is because I do not want the ACTION and METHOD submit on the form. I want to submit via AJAX so the user is not redirected to my PHP page.
Here is my HTML:
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"> </script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
<script>
$(document).ready(function () {
$("button#submit").click(function(){
$.ajax({
type: "POST",
url: "email.php", //
data: $('form.icontact').serialize(),
success: function(msg){
$("#thanks").html(msg)
$("#contact").modal('hide');
},
error: function(){
alert("failure");
}
});
});
});
</script>
</head>
<body>
<div class="container"> <!-- numbers cannot total more than 12 for rows-->
<div id="thanks"><p>Submit!</p></div>
</div>
<!--contact modal-->
<div class="modal fade"id="contact" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form class ="form-horizontal" name="icontact" id="icontact">
<div class="modal-header">
<h4>testemail</h4>
</div>
<div class="modal-body">
<p>Please enter your email address and click submit to receive your free first chapter</p>
<div class="form-group">
<label for ="contact-email" class="col-lg-2 control-label">Email: </label>
<div class="col-lg-10">
<input type="email" class="form-control" id="fromaddress" placeholder="new#example.com" name="fromaddress" />
<input type="hidden" id ="subject" value="enter in your email" name="subject" />
</div>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-default" data-dismiss="modal">Cancel</a>
<button class="btn btn-primary" type="submit" id="submit">Send</button>
</div>
</form>
</div>
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script src="js/bootstrap.js"></script>
</body>
and here is the php file. I get failure when I run it and it is passing the data in the URL like a GET. What am I doing wrong?
<?php
function spamcheck($field) {
// Sanitize e-mail address
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
// Validate e-mail address
if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
return TRUE;
} else {
return FALSE;
}
}
if (isset($_POST["fromaddress"])) {
// Check if "from" email address is valid
$mailcheck = spamcheck($_POST["fromaddress"]);
if ($mailcheck==FALSE) {
echo "Invalid input";
} else {
echo "<span class=\"alert alert-success\" >Your message has been received. Thanks!</span><br><br>";
$from = strip_tags($_POST["fromaddress"]); // sender
$subject = strip_tags($_POST["subject"]);
$message = "Thanks.";
// message lines should not exceed 70 characters (PHP rule), so wrap it
$message = wordwrap($message, 70);
// send mail
mail("test#test.com",$subject,$message,"From: $from\n");
}
}
?>
The problem is, you form is submitting either ways. You haven't prevented the default behaviour of the submit button. i.e. Submitting the form and redirecting to the form-action.
Do something like this
$("button#submit").click(function(e){
e.preventDefault(); // This line avoids the default submit event.
//Rest of stuff as you have it.....
});
A better option is to do the AJAX call on the .submit() rather than on the .click() as below
$("form#icontact").submit(function(e){
e.preventDefault();
//Proceed with other stuff as is...
});
Hope this helps! :)

jquery recaptcha php

I don't know how can i validate the recaptcha thing via jQuery. Please help. I have the contact us form with the following fields:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#signup').validate({
rules: {
name: {
required: true
},
email: {
required: true,
email: true
},
messages: {
name: {
required: 'FULL NAME Missing'
},
email: {
required: "E-MAIL ADDRESS Missing",
email: "E-MAIL ADDRESS Not Valid"
}
});
});
</script>
<form action="index.php" method="post" name="signup" id="signup">
<p>
Full Name
<br>
<input name="name" type="text" class="required" id="name" title="Type your Full Name into this box" value="<?php echo $_POST['name']; ?>">
</p>
<p>
E-Mail Address
<br>
<input name="email" type="text" id="email" title="Type your E-Mail Address into this box" value="<?php echo $_POST['email']; ?>">
</form>
Validation with the jQuery is working, but no idea how to implement the recaptcha into this.
thanks all for your comments,will get it done by simple library :)
http://www.white-hat-web-design.co.uk/articles/php-captcha.php
And validation by using php after submitting of the form (it was easy for me to implement in less time in php than jquery. :) .
special thanks to Felix Kling :).
Dave
For those sort of validate, there is a validation method in jQuery validate plugin known as remote.
Check it here
$("#myform").validate({
rules: {
email: {
required: true,
email: true,
remote: "check-email.php"
}
}
});
In this check-email.php should return string "true" to be considered valid. and string "false" to be considered false.

Categories