0

Actually this is first time to implement Ajax in drupal. I would like to implement a user name validation using Ajax in user register section. When a user enter his name and filling another field, then validation is running and if the user name already existing in the system, then a error message shows, the user name is already taken. I used to call the Validation function on "blur" event of Jquery. The Jquery cod is below

$("#edit-name").blur(function()
{
$.post(Drupal.settings.basePath + "username_checking",{user_name:$(this).val()} ,function(data)
    {
if(data=='no') //if username not avaiable
      {
        $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
        { 
          //add message and change the class of the box and start fading
           $(this).removeClass();
          $(this).addClass('messageboxerror');
          $(this).html('<img align="absmiddle" src="images/Error.png" /> Username Not Available...').show().fadeTo(1900,1);
          disable();
        });     
      }
 }              
    });
 }
});

and I implemented the function in a hook menu as below,

    $items['username_checking'] = array(
'title' => 'username_availability',
'page callback' => 'username_availability',
'access arguments' => array('access caubo_registration content'),
'type' => MENU_CALLBACK
);

and function is here

function username_availability() {
$user_name = $_POST['user_name'];
$select = "SELECT name FROM name WHERE user_name='%s' LIMIT '%d'";
$result = db_query($select,$user_name,1);   
$node = db_fetch_object($result);
if($node->name = $user_name){
  return "yes";
}
else{
  return "no";
}
}

It shows the error in Firebud

POST http://localhost/WC/drupal_website/username_checking
403 Forbidden

I want to confirm is my method is right or not ? If right please solve the problem, or give the exact way to do.

2

if this is a registration function for anonymous users do they have the respective access caubo_registration content permission set in User Permissions?

0

you might want to take a look how username_check implemented the ajax call or even use that module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.