Hi,
My form has an email field. When user is entering the email I would like to check if his email is already in the database.(form connected to its own db)
If the email was already used would be good to give a warning message: This email is already in use.
I searched the forum and found some help however would be nice to point to the right direction.
Thanks very much and have a great 2011.
My form has an email field. When user is entering the email I would like to check if his email is already in the database.(form connected to its own db)
If the email was already used would be good to give a warning message: This email is already in use.
I searched the forum and found some help however would be nice to point to the right direction.
Thanks very much and have a great 2011.
Thanks very much greyhead... just what i needed🙂 i owe you a beer indeed...will definitely send some £
Thanks again
m
Thanks again
m
Hi GH,
I tried to implement the code form your guide however it is not working. Something happening as I enter non valid eamil the email field responses but it doesn't check the DB.
I copied here all what i did.(my form name is reg_check) Would you be kind to take a quick look.
MY FORM CODE:
FORM Javascript:
Extra Form code 1:
I tried to implement the code form your guide however it is not working. Something happening as I enter non valid eamil the email field responses but it doesn't check the DB.
I copied here all what i did.(my form name is reg_check) Would you be kind to take a quick look.
MY FORM CODE:
<div class="form_item">
<div class="form_element cf_textbox">
<p>
<label class="cf_label"
style="width: 150px;">Email</label>
<input class="cf_inputbox" maxlength="150" size="30"
title="" id="email" name="email" type="text" />
</p>
<p>Name:
<label for="name"></label>
<input type="text" name="name" id="name">
</p>
<p>
<input type="submit" name="submit" id="submit" value="Submit">
</p>
</div>
<div class="cfclear">Â </div>
</div>
FORM Javascript:
window.addEvent('domready', function() {
// set the url to send the request to
var url = 'index.php?option=com_chronocontact&chronoformname=reg_check&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', 'blue');
}
}
}).send({'email': email.value});
} else {
// if this isn't a valid email set background color red
email.setStyle('background-color', 'yellow');
}
});
});
Extra Form code 1:
<?php
// clean up the JSON message
$json = stripslashes($_POST['json']);
$json = json_decode($json);
$email = strtolower(trim($json->email));
// check that the email field isn't empty
$response = false;
if ( $email ) {
// Check the database
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__users`
WHERE LOWER(`email`) = ".$db->quote($email).";
";
$db->setQuery($query);
$response = (bool) !$db->loadResult();
}
$response = array('email_ok' => $response );
//send the reply
echo json_encode($response);
// stop the from running
$MyForm->stopRunning = true;
die;
?>
Hi mojohand,
I copied and pasted it into a new form and it works OK here. I did have to set "Load Chronoforms CSS/JS Files?" to 'Yes' on the Form General tab.
Bob
I copied and pasted it into a new form and it works OK here. I did have to set "Load Chronoforms CSS/JS Files?" to 'Yes' on the Form General tab.
Bob
Hi Bob,
Thanks very much for your quick reply. I enabled Load Chronoforms CSS/JS Files?. Still no success.
Is there any file for ajax or json that I have to upload or ask the server guys to enable?
M
Thanks very much for your quick reply. I enabled Load Chronoforms CSS/JS Files?. Still no success.
Is there any file for ajax or json that I have to upload or ask the server guys to enable?
M
Hi mojohand,
Well, MooTools needs to be loaded but that's all as far as I remember.
Please post a link to the form so we can take a quick look.
Bob
Well, MooTools needs to be loaded but that's all as far as I remember.
Please post a link to the form so we can take a quick look.
Bob
Hi Bob,
You are so very helpful. I will make sure that some payment goes over as it is not a simple support issue at all.
The url of the form is http://www.ravaluk.com/index.php?option=com_chronocontact&chronoformname=reg_check
if you would like to look into the admin section
un: admin
pw: xxxxxx
thanks again
m
You are so very helpful. I will make sure that some payment goes over as it is not a simple support issue at all.
The url of the form is http://www.ravaluk.com/index.php?option=com_chronocontact&chronoformname=reg_check
if you would like to look into the admin section
un: admin
pw: xxxxxx
thanks again
m
Hi Mojohand,
It appears to be working OK in FireFox & Chrome and in IE without the template but IE with the template shows a JavaScript error from the Qluetip code: "'Class' is undefined (line 1)"
Bob
PS I removed the admin password, best not to post those in public ever. PM or email them to me if you need to.
It appears to be working OK in FireFox & Chrome and in IE without the template but IE with the template shows a JavaScript error from the Qluetip code: "'Class' is undefined (line 1)"
Bob
PS I removed the admin password, best not to post those in public ever. PM or email them to me if you need to.
Hi Bob,
Thanks very much. It's working indeed. Such a relieve🙂
One more question: Is it possible to add a script to go to two different url?
If the email is in the db go to url1
if it is not in the db go to url2
Cheers
M
Thanks very much. It's working indeed. Such a relieve🙂
One more question: Is it possible to add a script to go to two different url?
If the email is in the db go to url1
if it is not in the db go to url2
Cheers
M
Hi mojohand ,
Yes it is, but can you say a bit more about how you want this to work?
You can set a redirect after the form submits based on a value in the form. To do this you'd need to add a code snippet to set the value of a hidden input when the email is checked.
Bob
Yes it is, but can you say a bit more about how you want this to work?
You can set a redirect after the form submits based on a value in the form. To do this you'd need to add a code snippet to set the value of a hidden input when the email is checked.
Bob
Hi Bob,
Thanks for this indeed. The task is if the email field turns to blue meaning the email is already in the database the form takes to url 1. (where i have already a form without registration and a simple thank you page)
If the email turns to green so it is not in the db the form takes you to url 2 where i have an other form with registration and a complimentary voucher. I have the forms already with all the email responders, I only have to direct the users with this email checker form.
Thanks very much for looking into this.
M
Thanks for this indeed. The task is if the email field turns to blue meaning the email is already in the database the form takes to url 1. (where i have already a form without registration and a simple thank you page)
If the email turns to green so it is not in the db the form takes you to url 2 where i have an other form with registration and a complimentary voucher. I have the forms already with all the email responders, I only have to direct the users with this email checker form.
Thanks very much for looking into this.
M
Hi mojohand,
Add a new hidden input to the Form HTML
Then in the OnSubmit Before box (set 'Send Emails' to 'Yes' on the form General tab to make sure this runs). Add this code
Bob
Add a new hidden input to the Form HTML
<input type='hidden' name='new' id='new' value='<?php echo $new; ?>' />
Then you can edit the JavaScript here // check the result and set the background color
if ( r.email_ok ) {
email.setStyle('background-color', 'green');
$('new').value = 'yes';
} else {
email.setStyle('background-color', 'blue');
$('new').value = 'no';
}
Then in the OnSubmit Before box (set 'Send Emails' to 'Yes' on the form General tab to make sure this runs). Add this code
<?php
$new = JRequest::getString('new', '', 'post');
if ( $new == 'yes' ) {
$url = 'xxx';//insert url
} else {
$url = 'yyy';//insert url
}
$MyForm->formrow->redirecturl = $url;
?>
Bob
... finally it works also for me ... but i have some problem ... i delete all record from connected table but somehow it remembers previous email which i wrote before, why? I tried it also in different browsers ... it is same result, it remembers my email ... i am working on localhost. Thanks so much.
... now i discovered that in one and the same email address the place became blue, i tried write others emails every time is green but also when i used other email twice ... for example. [email]carot@carot.cc[/email] ... every time blue, blue ... now i will write another email address [email]banana@banana.ba[/email], [email]big@big.bg[/email] ... evrytime gree ... now i will use again [email]banana@banana.ba[/email] it supposed to be already blue, but is green ...
Hi hudakpavol,
I'm not sure that you've posted a question yet?
Please post the code that you are using to test this.
Bob
I'm not sure that you've posted a question yet?
Please post the code that you are using to test this.
Bob
From HTML:
From JAVA:
FROM Extra code 1:
<div class="form_item">
<div class="form_element cf_heading">
<h1 class="cf_text">Formular for section - PHOTO</h1>
</div>
<div class="cfclear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Name</label>
<input class="cf_inputbox required validate-alpha" maxlength="150" size="30" title="" id="text_2" name="text_2" type="text" />
</div>
<div class="cfclear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Second Name</label>
<input class="cf_inputbox required validate-alpha" maxlength="150" size="30" title="" id="text_3" name="text_3" type="text" />
</div>
<div class="cfclear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">Curent Section</label>
<select class="cf_inputbox validate-selection" id="select_4" size="1" title="" name="select_4">
<option value="">Choose Option</option>
<option value="GS 6A">GS 6A</option>
<option value="GS 6B">GS 6B</option>
<option value="GS 6C">GS 6C</option>
<option value="GS 6D">GS 6D</option>
<option value="GS 6E">GS 6E</option>
<option value="GS 6F">GS 6F</option>
<option value="HS 1A">HS 1A</option>
<option value="HS 1B">HS 1B</option>
<option value="HS 1C">HS 1C</option>
<option value="HS 1D">HS 1D</option>
<option value="HS 1E">HS 1E</option>
<option value="HS 2A">HS 2A</option>
<option value="HS 2B">HS 2B</option>
<option value="HS 2C">HS 2C</option>
<option value="HS 2D">HS 2D</option>
<option value="HS 2E">HS 2E</option>
<option value="HS 3A">HS 3A</option>
<option value="HS 3B">HS 3B</option>
<option value="HS 3C">HS 3C</option>
<option value="HS 3D">HS 3D</option>
<option value="HS 3E">HS 3E</option>
</select>
</div>
<div class="cfclear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_dropdown">
<label class="cf_label" style="width: 150px;">This Club will be my</label>
<select class="cf_inputbox validate-selection" id="select_5" size="1" title="" name="select_5">
<option value="">Choose Option</option>
<option value="First Club">First Club</option>
<option value="Second Club">Second Club</option>
</select>
</div>
<div class="cfclear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_textbox">
<label class="cf_label" style="width: 150px;">Your active email</label>
<input class="cf_inputbox required validate-email" maxlength="150" size="30" title="" id="email" name="email" type="text" />
</div>
<div class="cfclear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_captcha">
<label class="cf_label" style="width: 150px;">Rerite black letters, use small or capital letters.</label>
<span>{imageverification}</span>
</div>
<div class="cfclear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_button">
<input value="Submit" name="button_14" type="submit" />
</div>
<div class="cfclear">Â </div>
</div>
From JAVA:
window.addEvent('domready', function() {
// set the url to send the request to
var url = 'index.php?option=com_chronocontact&chronoformname=photovideo&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', 'blue');
}
}
}).send({'email': email.value});
} else {
// if this isn't a valid email set background color red
email.setStyle('background-color', 'yellow');
}
});
});
FROM Extra code 1:
<?php
// clean up the JSON message
$json = stripslashes($_POST['json']);
$json = json_decode($json);
$email = strtolower(trim($json->email));
// check that the email field isn't empty
$response = false;
if ( $email ) {
// Check the database
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(*)
FROM `#__users`
WHERE LOWER(`email`) = ".$db->quote($email).";
";
$db->setQuery($query);
$response = (bool) !$db->loadResult();
}
$response = array('email_ok' => $response );
//send the reply
echo json_encode($response);
// stop the from running
$MyForm->stopRunning = true;
die;
?>
Hi hudakpavol ,
I put your code into a form and it seems to work exactly as it should. If the address is in the jos_users table the box turns blue; if it isn't used in the jos_users table it turns green; if it isn't a valid email address it turns yellow.
I'm afraid that I still don't understand what your question is :-(
Bob
I put your code into a form and it seems to work exactly as it should. If the address is in the jos_users table the box turns blue; if it isn't used in the jos_users table it turns green; if it isn't a valid email address it turns yellow.
I'm afraid that I still don't understand what your question is :-(
Bob
... aha ... so I didnt know that script is checking jos_users table because my form is using this table for recording data ... jos_chronoforms_photovideo so i need to check this one ...
Hi hudakpavol,
Ah . . that makes sense :-)
You need to change the query in the Extra Code box to replace `#__users` with `#__chronoforms_photovideo`
Bob
Ah . . that makes sense :-)
You need to change the query in the Extra Code box to replace `#__users` with `#__chronoforms_photovideo`
$query = "
SELECT COUNT(*)
FROM `#__users`
WHERE LOWER(`email`) = ".$db->quote($email).";
";
Bob
Thank you Bob ... its working well ... I want to ask If I want to add new warn message when the email is already in the records, for example "Your email is already use in my database" and the button will be not active... like in case if the field is required ??
Hi hudakpavol,
You can edit this part of the JavaScript to do pretty much anything. Here it shows a matching error message:
Bob
You can edit this part of the JavaScript to do pretty much anything. Here it shows a matching error message:
// check the result and set the background color
if ( r.email_ok ) {
email.setStyle('background-color', 'green');
} else {
email.setStyle('background-color', 'blue');
var email_message = new Element('span', {
'styles': {
'display' : 'inline'
},
'class' : 'LV_validation_message LV_invalid'
});
email_message.setHTML('This email is already in use');
email_message.injectAfter(email);
}
}
Bob
Hi Bob its work fine ... but how can i disable button Submit because even if the email already exists in database ... you can submit formullar ... and I would like to stop it until there will be correct email.
window.addEvent('domready', function() {
// set the url to send the request to
var url = 'index.php?option=com_chronocontact&chronoformname=photovideo&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');
var email_message = new Element('span', {
'styles': {
'display' : 'inline'
},
'class' : 'LV_validation_message LV_invalid'
});
email_message.setHTML('This email is already in use');
email_message.injectAfter(email);
}
}
}).send({'email': email.value});
} else {
// if this isn't a valid email set background color red
email.setStyle('background-color', 'yellow');
}
});
});
Hi hudakpavol,
You need to have an id set for the submit button e.g. id='submit'
Bob
You need to have an id set for the submit button e.g. id='submit'
// check the result and set the background color
if ( r.email_ok ) {
email.setStyle('background-color', 'green');
$('submit').disabled = false; /* <-- add this line */
} else {
email.setStyle('background-color', 'blue');
$('submit').disabled = true; /* <-- add this line */
var email_message = new Element('span', {
'styles': {
'display' : 'inline'
},
'class' : 'LV_validation_message LV_invalid'
});
Bob
Thank so much , ... excellent ... 😀
This topic is locked and no more replies can be posted.