I have converted this hack to work with Virtuemart 1.0.15.
It seems to work ok!!
I have also added a "Confirm Email" box.
in administrator/components/com_virtuemart/checkout_register_form.php
Find:
if (!empty( $missing )) {
echo "<script type=\"text/javascript\">alert('".$VM_LANG->_CONTACT_FORM_NC."'); </script>\n";
}
Replace with:
?>
<script language="javascript" type="text/javascript">
<?php global $mosConfig_live_site; ?>
function getUsername(){
var form = document.adminForm;
var uname = form.username.value;
if( !$('username_ticker') )
$('username_div').innerHTML = $('username_div').innerHTML + "<div id=\"username_ticker\" class=\"<?php if ($page == 'shop.registration') {
echo 'usernameajax'; /*Need to change for your template*/
}
else {
echo 'usernameajax2'; /*Need to change for your template*/
} ?>
\"></div>";
$('username_field').value = uname;
if( form.username.value.length < 3 ) {
$('username_ticker').innerHTML = '<span style="background:#FFFFCC url(./images/publish_x.png) no-repeat 6px 6px; border:1px solid #CC0000;color:red;font-weight:bold;padding:5px 5px 5px 25px; float:left;">More than 2 characters!</span>';
} else {
$('username_ticker').innerHTML = "<img src=\"<?php echo $mosConfig_live_site; ?>/images/wait.gif\"> Checking";
var url = 'index.php?option=com_virtuemart&task=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 url(./images/publish_x.png) no-repeat 6px 6px; border:1px solid #CC0000;color:red;font-weight:bold;padding:5px 5px 5px 25px;float:left;">Already Used!</span>';
} else {
$('username_ticker').innerHTML = '<span style="background:#FFFFCC url(./images/tick.png) no-repeat 6px 6px; border:1px solid #390; color:green;font-weight:bold;padding:5px 5px 5px 25px;float:left;">Available.</span>';
}
}
}).request();
}
}
function getEmail(){
var form = document.adminForm;
var email = form.email.value;
if( !$('email_ticker') )
$('email_div').innerHTML = $('email_div').innerHTML + "<div id=\"email_ticker\" class=\"<?php if ($page == 'shop.registration') {
echo 'useremailajax'; /*Need to change for your template*/
}
else {
echo 'useremailajax2'; /*Need to change for your template*/
} ?>
\"></div>";
$('email_field').value = email;
if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value))) {
$('email_ticker').setHTML('<span style="background:#FFFFCC url(./images/publish_x.png) no-repeat 6px 6px;border:1px solid #CC0000;color:red;font-weight:bold;padding:5px 5px 5px 25px;float:left;">Not Valid!</span>');
} else {
$('email_ticker').setHTML("<img src=\"<?php echo $mosConfig_live_site; ?>/images/wait.gif\"> Checking");
var url = 'index.php?option=com_virtuemart&task=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 url(./images/publish_x.png) no-repeat 6px 6px; border:1px solid #CC0000;color:red;font-weight:bold;padding:5px 5px 5px 25px;float:left;">Already Registered.</span>');
} else {
$('email_ticker').setHTML('<span style="background:#FFFFCC url(./images/tick.png) no-repeat 6px 6px; border:1px solid #390; color:green;font-weight:bold;padding:5px 5px 5px 25px;float:left;">Not Registered.</span>');
}
}
}).request();
}
}
</script>
<?php
if (!empty( $missing )) {
echo "<script type=\"text/javascript\">alert('".$VM_LANG->_('CONTACT_FORM_NC',false)."'); </script>\n";
}
You will need to change the classes to suit your template /*Need to change for your template*/
The classes I used for my template.css were:
.usernameajax {position:absolute; top:505px; left:630px; z-index:6000;}
.usernameajax2 {position:absolute; top:635px; left:480px; z-index:6000;}
.useremailajax {position:absolute; top:535px; left:630px; z-index:6000;}
.useremailajax2 {position:absolute; top:665px; left:480px; z-index:6000;}
In the same file find:
$shopper_fields['email'] = $VM_LANG->_REGISTER_EMAIL;
Add directly below:
$shopper_fields['email2'] = $VM_LANG->_REGISTER_EMAIL2;
Find:
case 'agreed':
echo '<input type="checkbox" id="agreed_field" name="agreed" value="1" class="inputbox" />';
break;
Add directly below:
case 'email':
echo '<input type="text" id="'.$fieldname.'_field" name="'.$fieldname.'" size="30" onchange="getEmail();" value="'. ($db->sf($fieldname, true, false)?$db->sf($fieldname, true, false):'') .'" class="inputbox" />'."\n";
break;
case 'email2':
echo '<input type="text" id="'.$fieldname.'_field" name="'.$fieldname.'" size="30" class="inputbox" />'."\n";
break;
case 'username':
echo '<input type="text" id="'.$fieldname.'_field" name="'.$fieldname.'" size="30" onchange="getUsername();" value="'. ($db->sf($fieldname, true, false)?$db->sf($fieldname, true, false):'') .'" class="inputbox" />'."\n";
break;
in file administrator/components/com_virtuemart/htmlTools.class.php
Find:
if( in_array( 'email', $required_fields)) {
echo '
if( !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value))) {
alert( \''. html_entity_decode( $VM_LANG->_REGWARN_MAIL ).'\');
return false;
}';
}
Add after:
if( in_array( 'email2', $required_fields)) {
echo '
if (form.email2.value == "") {
alert( "'.html_entity_decode( $VM_LANG->_REGWARN_MAIL2).'" );
return false;
} else if ((form.email.value != "") && (form.email.value != form.email2.value)){
alert( "'. html_entity_decode( $VM_LANG->_REGWARN_MAIL3).'" );
return false;
}';
}
in file administrator/components/com_virtuemart/languages/english.php
Find:
var $_REGISTER_EMAIL = 'Email';
Add after:
var $_REGISTER_EMAIL2 = 'Confirm E-mail';
find:
var $_REGWARN_MAIL = 'Please enter a valid e-mail address!';
Add after:
var $_REGWARN_MAIL2 = 'Please confirm your e-mail!';
var $_REGWARN_MAIL3 = 'E-mail confirmation does not match, please try again!';
in file components/com_virtuemart/virtuemart.php
Find:
include( $mosConfig_absolute_path.'/administrator/components/'.$option.'/compat.joomla1.5.php');
Add after:
$task = mosGetParam($_REQUEST, 'task' );
if($task=="chkuserinfo"){
global $database;
$email = mosGetParam($_REQUEST, 'email' );
$uname = mosGetParam($_REQUEST, 'uname' );
$what = mosGetParam($_REQUEST, '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();
}
I think that's all!!!!