Author Topic: [SOLVED] ajax registration  (Read 96845 times)

woonydanny

  • Jr. Member
  • **
  • Posts: 110
[SOLVED] ajax registration
« on: August 17, 2009, 14:03:26 pm »
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.

woonydanny

  • Jr. Member
  • **
  • Posts: 110
Re: ajax registration
« Reply #1 on: September 15, 2009, 10:49:10 am »
would still really like this ajax username/email checker to be integrated into virtuemart :)

woonydanny

  • Jr. Member
  • **
  • Posts: 110
[SOLVED]Re: ajax registration
« Reply #2 on: September 26, 2009, 09:47:49 am »
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: [Select]
$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: [Select]
$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";?>\">&nbsp;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";?>\">&nbsp;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: [Select]
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: [Select]
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: [Select]
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: [Select]
$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


[attachment cleanup by admin]

Branson

  • Beginner
  • *
  • Posts: 21
Re: [SOLVED] ajax registration
« Reply #3 on: October 04, 2009, 00:58:10 am »
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...

[attachment cleanup by admin]

woonydanny

  • Jr. Member
  • **
  • Posts: 110
Re: [SOLVED] ajax registration
« Reply #4 on: October 04, 2009, 01:26:17 am »
cheers Branson, i have now updated the last file's path.

glad it works for you too!

Ventsi Genchev

  • Jr. Member
  • **
  • Posts: 308
    • Audio Store
Re: [SOLVED] ajax registration
« Reply #5 on: October 04, 2009, 08:30:15 am »
You're the man! Exactly what I needed. Thank you very much.
Audio Store:
https://vsystem.bg - Bulgarian language
https://vsystem.bg/en - English

Branson

  • Beginner
  • *
  • Posts: 21
Re: [SOLVED] ajax registration
« Reply #6 on: October 20, 2009, 05:57:53 am »
Just upgraded from 1.1.13 to 1.1.14 (patched). The edited files got overwritten during the upgrade, as expected.

I went through the instructions and it works great in 1.1.14. In case anyone is wondering.

woonydanny

  • Jr. Member
  • **
  • Posts: 110
Re: [SOLVED] ajax registration
« Reply #7 on: October 20, 2009, 10:22:09 am »
hmmm, even though i have this working for me (tested it a fair bit) i have had numerous emails from customers saying that cant register.

Saying that they cant click on Submit Registration button and the Submit Registration button doesnt appear on some occasions. I cant replicate these issues but was hoping someone might be able to let me know what could be causing this?

thanks

woonydanny

  • Jr. Member
  • **
  • Posts: 110
Re: [SOLVED] ajax registration
« Reply #8 on: October 20, 2009, 15:21:24 pm »
ok i am pretty sure i am having problems due to https.

the freelance developer is not responding (as i have already paid him) so any help much appreciated to fix this

woonydanny

  • Jr. Member
  • **
  • Posts: 110
Re: [SOLVED] ajax registration
« Reply #9 on: October 20, 2009, 15:48:04 pm »
ok further testing has revealed that it doesnt work (no Submit Registration button is shown) when i use the registration form from the Checkout where it has the option for Returning Customers. Obviously there is a javascript conflict or something with that and the hack.

If i register through the Register link on the module (so doesnt have the returning customers feature) then it seems to work.

anyone know how to fix this?

Branson

  • Beginner
  • *
  • Posts: 21
Re: [SOLVED] ajax registration
« Reply #10 on: October 20, 2009, 19:59:19 pm »
i will take a look at this tonight. im not a good programmer, but i can read it and see where it may be having issues.

what joomla template are you using, and do you think it may be that causing the issue?

chuckscroggs

  • Beginner
  • *
  • Posts: 22
Re: [SOLVED] ajax registration
« Reply #11 on: October 23, 2009, 20:46:49 pm »
How do we get this USERNAME CHECKER to work on the actual registration page and not just the one they go to when they are checking out?

woonydanny

  • Jr. Member
  • **
  • Posts: 110
Re: [SOLVED] ajax registration
« Reply #12 on: October 24, 2009, 03:38:21 am »
it works on the shop registration page, so just use the VM login module and people will use the shop rego page.

still having a problem with the javascript conflicting with the returning customers code so IE doesnt work

Scar

  • Full Member
  • ***
  • Posts: 1035
    • J-lux
Re: [SOLVED] ajax registration
« Reply #13 on: October 28, 2009, 16:44:21 pm »
I haven't tried this yet but there is a "e" missing in this line:
$('username_field').value   = unam;

in the insert code in administrator/components/com_virtuemart/html/checkout_register_form.php

sev

  • Beginner
  • *
  • Posts: 7
Re: [SOLVED] ajax registration
« Reply #14 on: November 26, 2009, 12:30:48 pm »
it works on the shop registration page, so just use the VM login module and people will use the shop rego page.

I tried this and it works beautifully during checkout, but does not/not work when registering through VM registration module (either as part of all_in_one or stand alone).

I am on VM 1.1.4 and Joomla 1.5.15.

Any advice?