Ok Andy I'll give you the instructions to make the ajax check yourself. As I wrote before the inputclear() function gets broken, but this results only in missing the grey labeltexts after focussing once.
Step 1) Add the onblur function we are going to make to the username and the email field by changing line 206 of /onepage/themes/yourthemefolder/overrides/list_user_fields.tpl.php to:
- Code: Select all
echo str_replace('type=', ' autocomplete="off" onblur="registercheck()" type=', $field['formcode']);
Step 2) Add this function I named registercheck to a javascript file. I choose to add it to tabcontent.js because that is also within my theme folder:
- Code: Select all
function registercheck()
{
var emailadres = document.getElementById('email_field').value;
new Request.HTML({
method: 'post',
url: 'index.php?option=com_yourcomponent&task=registercheckemail&format=raw',
data: { 'emailadres': emailadres },
onSuccess: function() {
var json = JSON.parse(this.response.html);
var exists = json.resultaat.bestaat;
var message = json.resultaat.melding;
if(this.response.html == 'ok')
{
$('email_div').set('text', '');
document.getElementById('email_div').className = 'formLabel ';
}
else
{
$('email_div').set('text', exists);
document.getElementById('email_div').className = 'formLabel missing';
new MooDialog.Alert(message);
}
}
}).post();
}
!mind some Dutch spelling in the vars and the json.
This function makes use of an event to run the php. You can just create a php file for that, but using a component with some protection is better ofcourse! The protection is already questionable because the function can be used over and over again to see if emailaddresses has been registered...
Step3) Create Event
- Code: Select all
function registercheckemail() {
$emailadres = $_POST[emailadres];
//query to check email exists
$db =& JFactory::getDBO();
$query = "SELECT 1 FROM #__users WHERE email='$emailadres' LIMIT 1";
$db->setQuery($query);
$result = $db->loadResult();
If ( $result == 1 )
{
$output = '{"resultaat": {
"bestaat": "'.JText::_('COM_LJ_ERROR').'",
"melding": "'.JText::_('COM_LJ_ALERT_EMAIL_EXISTS').'"
}}';
}
else
{
$output = 'ok';
}
echo $output;
}
The query only selects 1 row to be as lightweight as possible. The result is a json format, because I want to use the result as well as a multilanguage message back in the Javascript function. For the message I use Moodialog in my javascript, so change that to your own situation.
With this 'manual' you can make the ajaxcheck and add the extra function for the username in the php.
Good Luck!
Rolf