Username Ajax Check

Please post any feature requests here

Username Ajax Check

Postby andy871@.....com » Tue Apr 30, 2013 12:51 pm

I have read this feature request post here and chose not to add my thread to it as I think he is asking for something slightly different - viewtopic.php?f=3&t=439&p=1365&sid=cfbb13c9c0ad51961580a15b95ed324b#p1365

I think a great addition would be some sort of ajax check against the username when a new user is checking out.
I use the sandwitch theme & with the upgrade you(Stan) released last week, I can now have username in the checkout user registration form - which is great.

But some users have complained that when they tried a username they keep getting red error bar "username in use" so they have to keep trying until they find a username that is not in use.

If some sort of ajax message could pop up straight away, saying "username in use, choose another" or even green tick / red cross to indicate it is already in use?

Is this something that would interest other?
is this something that could be added in painlessly?

Thanks in advance,
Andy
andy871@.....com
 
Posts: 45
Joined: Wed Mar 27, 2013 4:28 pm

Re: Username Ajax Check

Postby rolf@.....eu » Mon May 06, 2013 2:42 pm

I've been trying to make this myself 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']);
for adding the onblur but then the function inputclear in /onepage/themes/tabcontent.js gets broken.

I hope Stan somebody else can give some instructions on how to add an extra onblur function to the email and username fields.

Rolf
rolf@.....eu
 
Posts: 12
Joined: Tue Feb 26, 2013 7:11 pm

Re: Username Ajax Check

Postby rolf@.....eu » Tue May 07, 2013 3:31 pm

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
rolf@.....eu
 
Posts: 12
Joined: Tue Feb 26, 2013 7:11 pm

Re: Username Ajax Check

Postby andy871@.....com » Wed May 08, 2013 11:38 am

Thanks for sharing your ideas Rolf, I'll give them a go in my test site this afternoon!

Andy
andy871@.....com
 
Posts: 45
Joined: Wed Mar 27, 2013 4:28 pm

Re: Username Ajax Check

Postby admin » Wed Jul 03, 2013 3:14 pm

hello friens, i apologize for not responding to this section of the forum sooner, but i had already added both ajax checks for the username AND email which can be enabled within the backend. if you had any issues with this, let me know at the main OPC2 forum section.

both features work in two ways:
- check and show the error message for username/email
- enable or disable the registration with such already existing username/email



best regards,
stan, rupostel.com
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm


Return to Feature Request

cron