[SOLVED] ajax registration
peetree21:
i know it is nearly stable, but is there the feature of an ajax username/email checker planned? As at present, when a person enters all the information and clicks Send Registration and they have chosen a username that is already taken you are taken to a page where you need to click the back button and fill out the whole form again.
peetree21:
would still really like this ajax username/email checker to be integrated into virtuemart :)
peetree21:
ok, i had a freelance developer write this hack for me. It works for me on IE7,IE8,FF3.5,Safari 4. I have included the instructions below for the community. I do not provide any support but I hope this helps some people and maybe even make it into the core.
FILE: administrator/components/com_virtuemart/html/checkout_register_form.php
Line 23 : CHANGE THESE LINEs
Code:
$missing = vmGet( $_REQUEST, "missing", "" );
if (!empty( $missing )) {
echo "<script type=\"text/javascript\">alert('".$VM_LANG->_('CONTACT_FORM_NC',false)."'); </script>\n";
}
AND REPLACE IT WITH THIS CODE:
Code:
$missing = vmGet( $_REQUEST, "missing", "" );
?>
<script language="javascript" type="text/javascript">
function getUsername(){
var form = document.adminForm;
var unam = form.username.value;
if( !$('username_ticker') )
$('username_input').innerHTML = $('username_input').innerHTML + "<div id=\"username_ticker\" style=\"padding-top:10px;\"></div>";
$('username_field').value = unam;
if( form.username.value.length < 3 ) {
$('username_ticker').innerHTML = '<span style="background:#FFFFCC;border:1px solid #CC0000;color:red;font-weight:bold;padding:5px 5px 5px 5px;">Username : This input value is not valid.</span>';
} else {
$('username_ticker').innerHTML = "<img src=\"<?php echo JURI::base()."images/wait.gif";?>\"> Checking";
var url = 'index.php?option=com_virtuemart&tasked=chkuserinfo&format=raw&what=uname';
url = url + '&uname=' + form.username.value;
new Ajax(url, {
method: 'get',
onComplete: function(x){
if(x == 1) {
$('username_ticker').innerHTML = '<span style="background:#FFFFCC;border:1px solid #CC0000;color:red;font-weight:bold;padding:5px 5px 5px 5px;">This username is already registered.</span>';
} else {
$('username_ticker').innerHTML = '<span style="border:1px none transparent;color:green;padding:5px 5px 5px 5px;">The username \''+ $('username_field').value +'\' is free for registration: you can proceed.</span>';
}
}
}).request();
}
}
function getEmail(){
var form = document.adminForm;
var eadd = form.email.value;
if( !$('email_ticker') )
$('email_input').innerHTML = $('email_input').innerHTML + "<div id=\"email_ticker\" style=\"padding-top:10px;\"></div>";
$('email_field').value = eadd;
if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value))) {
$('email_ticker').setHTML('<span style="background:#FFFFCC;border:1px solid #CC0000;color:red;font-weight:bold;padding:5px 5px 5px 5px;">Email : This input value is not valid.</span>');
} else {
$('email_ticker').setHTML("<img src=\"<?php echo JURI::base()."images/wait.gif";?>\"> Checking");
var url = 'index.php?option=com_virtuemart&tasked=chkuserinfo&format=raw&what=email';
url = url + '&email=' + form.email.value;
new Ajax(url, {
method: 'get',
onComplete: function(x){
if(x == 1) {
$('email_ticker').setHTML('<span style="background:#FFFFCC;border:1px solid #CC0000;color:red;font-weight:bold;padding:5px 5px 5px 5px;">This email is already registered.</span>');
} else {
$('email_ticker').setHTML('<span style="border:1px none transparent;color:green;padding:5px 5px 5px 5px;">The email \''+ $('email_field').value +'\' is free for registration: you can proceed.</span>');
}
}
}).request();
}
}
</script>
<?php
if (!empty( $missing )) {
echo "<script type=\"text/javascript\">alert('".$VM_LANG->_('CONTACT_FORM_NC',false)."'); </script>\n";
}
and then you need to add code into another file.
FILE: administrator/components/com_virtuemart/classes/ps_userfield.php
LINE 390 :
AFTER THESE LINES
Code:
case 'password':
case 'password2':
echo '<input type="password" id="'.$field->name.'_field" name="'.$field->name.'" size="30" class="inputbox" />'."\n";
break;
ADD THE CODES BELOW:
Code:
case 'email':
echo '<input type="text" id="'.$field->name.'_field" name="'.$field->name.'" size="30" class="inputbox" onchange="getEmail();" />'."\n";
break;
case 'username':
echo '<input type="text" id="'.$field->name.'_field" name="'.$field->name.'" size="30" maxlength="25" onchange="getUsername();" class="inputbox" />'."\n";
break;
SO IT SHOULD LOOK LIKE THIS:
Code:
case 'password':
case 'password2':
echo '<input type="password" id="'.$field->name.'_field" name="'.$field->name.'" size="30" class="inputbox" />'."\n";
break;
case 'email':
echo '<input type="text" id="'.$field->name.'_field" name="'.$field->name.'" size="30" class="inputbox" onchange="getEmail();" />'."\n";
break;
case 'username':
echo '<input type="text" id="'.$field->name.'_field" name="'.$field->name.'" size="30" maxlength="25" onchange="getUsername();" class="inputbox" />'."\n";
break;
default:
ANOTHER FILE TO HACK
FILE: /components/com_virtuemart/virtuemart.php
LINE 21 : INSERT THE CODE BELOW AFTER THIS CODE "global $mosConfig_absolute_path, $product_id, $vmInputFilter, $vmLogger;"
Code:
$tasked = JRequest::getVar( 'tasked' );
if($tasked=="chkuserinfo"){
$database = & JFactory::getDBO();
$email = JRequest::getVar( 'email' );
$uname = JRequest::getVar( 'uname' );
$what = JRequest::getVar( 'what' );
$usercount = 0;
$emailcount = 0;
if($what == "uname"){
$database->setQuery("SELECT COUNT(*) FROM #__users WHERE username='$uname'");
$usercount = $database->loadResult();
if($usercount)
echo "1";
else
echo "0";
} else if ($what == "email") {
$database->setQuery("SELECT COUNT(*) FROM #__users WHERE email='$email'");
$emailcount = $database->loadResult();
if($emailcount)
echo "1";
else
echo "0";
}
die();
}
ALSO MAKE SURE THE IMAGE BELOW IS UPLOADED INTO THE /images DIRECTORY ON YOUR SERVER
Branson:
VERY nice mod! I agree that this should be included in future releases.
One thing that you need to change is in the instructions. It states that the location of the last file to modify...
You have it listed as /components/virtuemart.php
This should be /components/com_virtuemart/virtuemart.php
Attached below is a screenshot of it in action...
peetree21:
cheers Branson, i have now updated the last file's path.
glad it works for you too!
Navigation
[0] Message Index
[#] Next page