check if email already in use

vivaasia 24 Mar, 2011
Hi Bob,

Have gone through a lot of the posts and am a bit confused have also looked at the http://greyhead.net/chronoforms/using-ajax-to-look-up-e-mail-addresses

I want to make sure that we are not getting multiple entries from the same email address in our competition. Where do I actually place the code that you have presented. Am I right in thinking that this is all the code together:
window.addEvent('domready', function() {
  // set the url to send the request to
  var url = 'index.php?option=com_chronocontact
    &chronoformname=form_name&task=extra&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 jSonRequest = new Json.Remote(url, {
        onComplete: function(r) {
          // check the result and set the background color
          if ( r.email_ok ) {
            email.setStyle('background-color', 'green');
          } else {
            email.setStyle('background-color', 'red');
          }
        }
      }).send({'email': email.value});
    } else {
      // if this isn't a valid email set background color red
      email.setStyle('background-color', 'red');
    }
  });
});


Jim
GreyHead 24 Mar, 2011
Hi Jim,

That looks like the entire JavaScript part - there's a PHP part in the Extra Code box and a part in the Form HTML as well.

Bob
This topic is locked and no more replies can be posted.