Lunarhotel.co.uk

How about a view of the sea of tranquility?
Home Joomla things Dealing with spam on the Virtuemart Ask a question about this product page - Making the changes
E-mail
Print
PDF
Written by Web Master   
Monday, 23 November 2009 18:31
User Rating: / 2
PoorBest 
Article Index
Dealing with spam on the Virtuemart Ask a question about this product page
Making the changes
All Pages

So we can see at line 20 there is a test to see if the form data has already been submitted. We're going to add a secondary condition, that is if the user is logged in, then display the form, otherwise invite the user to either login, or register.

Add the following lines to this file (at line 27)

 

<?php 
$userinfo=& JFactory::getUser();
if(!$userinfo->guest) { ?>

 

Your code should now look like this
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
mm_showMyFileName( __FILE__ );
?>
<div class="ask-question">
<div class="ask-question-inner">
<?php

if ( $set == 0 ) { // This is the enquiry form!

$validate = vmIsJoomla( '1.5' ) ? JUtility::getHash( $mainframe->getCfg( 'db' ) ) : mosHash( $mainframe->getCfg( 'db' ) );
?>
<a class="return-to-product" href="/<?php echo $product_link ?>"><?php echo $VM_LANG->_('VM_RETURN_TO_PRODUCT') ?></a>
<?php
$userinfo=& JFactory::getUser();
if(!$userinfo->guest) { ?>
<form action="<?php echo $mm_action_url ?>index.php" method="post" name="emailForm" id="emailForm">
<label for="contact_name"><?php echo $VM_LANG->_('NAME_PROMPT') ?></label>
<br /><input type="text" name="name" id="contact_name" size="80" class="inputbox" value="<?php echo $name ?>"><br /><br />
<label for="contact_mail"><?php echo $VM_LANG->_('EMAIL_PROMPT') ?></label>
<br /><input type="text" id="contact_mail" name="email" size="80" label="Your email" class="inputbox" value="<?php echo $email ?>"><br /><br />
<label for="contact_text"><?php echo $VM_LANG->_('MESSAGE_PROMPT') ?></label><br />
<textarea rows="10" cols="60" name="text" id="contact_text" class="inputbox"><?php echo $subject ?></textarea><br />


Now move down to line 50 (ish), you should see this code:

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<script type="text/javascript"><!--
function validateEnquiryForm() {
if ( ( document.emailForm.text.value == "" ) || ( document.emailForm.email.value.search("@") == -1 ) || ( document.emailForm.email.value.search("[.*]" ) == -1 ) ) {
alert( "<?php echo $VM_LANG->_('CONTACT_FORM_NC',false); ?>" );
} else if ( ( document.emailForm.email.value.search(";") != -1 ) || ( document.emailForm.email.value.search(",") != -1 ) || ( document.emailForm.email.value.search(" ") != -1 ) ) {
alert( "You cannot enter more than one email address" );
} else {
document.emailForm.action = "<?php echo sefRelToAbs("index.php"); ?>"
document.emailForm.submit();
}
}
--></script>

<?php
}
else { // if set==1 then we .... ..


Add the following lines, straight after line 61 in the above snippett. You'll need to get rid of the existing opening <?php tag.

Code to insert:

66
67
68
69
70
71
72
<?php
} else { ?>
Please <A href="/user/login.html">Login to ask a question</A>.
If you do not have an account,
<a href="/index.php?option=com_virtuemart&page=shop.registration&Itemid=54">
you can register here</a>.
<?php }


So it should now look like this

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<script type="text/javascript"><!--
function validateEnquiryForm() {
if ( ( document.emailForm.text.value == "" ) || ( document.emailForm.email.value.search("@") == -1 ) || ( document.emailForm.email.value.search("[.*]" ) == -1 ) ) {
alert( "<?php echo $VM_LANG->_('CONTACT_FORM_NC',false); ?>" );
} else if ( ( document.emailForm.email.value.search(";") != -1 ) || ( document.emailForm.email.value.search(",") != -1 ) || ( document.emailForm.email.value.search(" ") != -1 ) ) {
alert( "You cannot enter more than one email address" );
} else {
document.emailForm.action = "<?php echo sefRelToAbs("index.php"); ?>"
document.emailForm.submit();
}
}
--></script>
<?php
} else { ?>
Please <A href="/user/login.html">Login to ask a question</A>.
If you do not have an account, <a href="/index.php?option=com_virtuemart&page=shop.registration&Itemid=54">you can register here</a>.
<?php }
}
else { // if set==1 then we have sent the email to the vendor and say thank you here.
?>
<img src="/<?php echo VM_THEMEURL ?>images/button_ok.png" height="48" width="48" align="center" alt="Success" border="0" />
<?php echo $VM_LANG->_('THANK_MESSAGE') ?>
.
.
.

 

Save your file, upload it if you have to. Browse to one of your products and click on "Ask a question about this product" If you're logged in, it will present the form as normal, if you're not, we'll then it will ask you to login or register. There is an argument to say the user may decide they cant be bothered to login, or register, and a Captcha is far more suitable. I agree, and I've no doubt that the rather spiffing chaps at Virtuemart will put this feature in to the next release. Until then, Im opting for this method, and making registering / logging in easier for my customers by using our EmailAsUsername Plugin

If you're using the default Virtuemart template, Ive attached a pre-modified version. Just to stress, this is for Virtuemart 1.1.4. I havent tested it with any other versions.

 



Last Updated on Monday, 23 November 2009 21:29
 

You must register if you wish to comment

Its official! usernames suck!

12507Check out the 10 mile round trip I had to do to login into a site that was asking for a username and password

Whos online

We have 1 guest online

Joomla EmailAsUsername Testamonials

"Thanks for a great plugin, and speedy helpful support."

"I really appreciate how responsive you have been and I want to reward you by adding a very positive comment on the Joomla site where I found your great plugin"

"Wow, tested it out and works like a champ"

"I had a couple of installation issues which Dylan sorted for me the same afternoon. Superb service for the price."

"Thank you!!!  Best support I have ever had!"

"Thank you soooooo much for your time and effort on this, you're a life saver!....If your ever in the London or Guildford area I'll get the beers in!"