This is placed in the js loader in the on load event and is the first event:
window.addEvent('domready', function() {
// set the url to send the request to
var url = 'index.php?option=com_chronoforms&chronoform=parent_registration&event=ajax&format=raw';
var email = $('email');
email.addEvent('blur', function() {
// clear any background color from the input
email.setStyle('background-color', 'white');
// check that the email address is valid
regex = /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i;
var value = email.value.trim();
if ( value.length > 6 && regex.test(value) ) {
// if all is well send the JSON request
var request = new Request({
method: 'post',
url: url,
data: { 'email' : value },
onComplete: function(r) {
// check the result and set the background color
if ( r == 'ok' ) {
email.setStyle('background-color', 'green');
} else {
email.setStyle('background-color', 'red');
}
}
}).send();
} else {
// if this isn't a valid email set background color red
email.setStyle('background-color', 'red');
}
});
});
This is placed in custom code in a new event called on ajax and is the last event:
<?php
// get the query info
$email = JRequest::getString('email', '', 'post');
$email = strtolower(trim($email));
// check that the email field isn't empty
$response = 'in use';
if ( $email ) {
// Check the database
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__users`
WHERE LOWER(`email`) = ".$db->quote($email).";
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count == 0 ) {
$response = 'ok';
}
}
//send the reply
echo $response;
?>
There is an on submit event in the middle adding and retrieving data from the database and doing the captcha etc.
All that happens is that no matter what email I enter all that happens is the background of the email box turns red.
Any ideas where i may be going wrong?
I have purchased the how-to Doc from greyhead.net which is where I got the code from.