Sitting on this already the whole day, if you believe or not :) I want to transfer data via GET-Method to an external .jsp file (example.com/data.php?attribute=value&a2=v2 and so on)
This all seems to work so far and also the validation. Now I have the problem that I have a captcha which is generated by a php-file and the captcha is controlled/validated in the PHP-File where the HTML-Form data is posted to.
When everything is OK I can do a alert in the submitHandler (success: function(response)) but how can I get an alert now, if the Captcha is incorrect?
How can I solve this? Can I get a value oder variable throught AJAX back from the PHP File to do something with it (to display the alert)?
Would be very glad for any help or comments.
Thank you!
HERE the data is validated and sent to PHP file after successful validation.
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript">
(function($,W,D)
{
var JQUERY4U = {};
JQUERY4U.UTIL =
{
setupFormValidation: function()
{
$("#form-id").validate({
rules: {
firstname: "required",
.........
},
messages: {
firstname: "Please enter your firstname",
..........
},
submitHandler: function(form)
var data = $("#nachricht").serializeArray();
$.ajax({
type:"POST",
url:"nachricht.php",
data: data,
dataType: "text",
success: function(response) {
alert('Thank you!');
}
});
}
});
}
}
$(D).ready(function($) {
JQUERY4U.UTIL.setupFormValidation();
});
})(jQuery, window, document);
THE PHP FILE: Here the data is transferred to another URL (GET-Method) and the Captcha is checked
$email = urlencode($_POST['email']);
$name = urlencode($_POST["name"]);
....
session_start();
if(isset($_SESSION['captcha_spam']) AND $_POST["captchafield"] == $_SESSION['captcha_spam']) // Captcha korrekt
{
unset($_SESSION['captcha_spam']);
$link = "http://www.example.com/data.jsp?email=" . $email . "&name=" . $name . $titel . "&text=" . $text . "&ranking=" . $ranking . "&captchafield=" . $captcha_s;
header( "refresh:0;url=" . $link);
exit;
....