Forums

Disable imageverification if logged in

jeromebg 23 Jun, 2010
Hi there, is there a way to disable the image verification if a user is logged in ?
I made a form to submit content by email and would like to use the imageverification function for the users non logged to avoid spam, but I would like to diable this function if it's a known user (logged in)
Thanx for your help !!!
nml375 23 Jun, 2010
Hi,
This should be possible, but takes some creative coding to make it work.

The approach would be to disable the image verification, and manually add the code for the verification image (copy and paste from a form with im.ver. enabled?). Next step would then to use the serverside validation code. Fetch the current user's object (JFactory::getuser()), and test the id-propery for 0. If it is 0, test the md5-hash of the verification code against the hash stored in the session object.

I'm currently on a mobile client, but I'll see about some code examples later in the evening. Otherwize, you'll find the different bits and pieces lurking in the ChronoForms sourcecode.

/Fredrik
jeromebg 23 Jun, 2010
Wow... thanx for your help !
But that's chineese to me am afraid...
If it's that difficult then users will have to type the imageverification code then !
GreyHead 23 Jun, 2010
Hi jeromebg,

There's another possibility which may be simpler. You can make a copy of your form (Form 2) and remove the Imageverification. Then at the beginning of Form 1 check if the user is logged in and, if they are redirect them to Form 2.

Similarly at the beginning of Form 2 redirect any un-logged in users over to Form 1.

Bob
nml375 23 Jun, 2010
Hi,
Actually, the needed code isn't that terribly complex.

Anyway, the code examples as promised:
Form Code - where you'd like the captcha image to appear:
<?php
$user =& JFactory::getUser();
if ($user->id == 0) {
  echo '  <div class="form_element cf_captcha">

    <label class="cf_label" style="width: 150px;">Image verification</label>
    <span>
<input name="chrono_verification" style="vertical-align:top;" type="text" id="chrono_verificaton" value="" />  <img src="'.$CF_PATH.'components/com_chronocontact/chrono_verification.php?imtype=1" alt="" />
</span> 
    
    </div>
  <div class="cfclear"> </div>
</div>';
}
?>


Serverside Validation:
<?php
$user =& JFactory::getUser();
$sess =& JFactory::getSession();

if ($user->id == 0) {
  $hash = $sess->get('chrono_verification', '', md5('chrono'));
  $capt = JRequest::getVar('chrono_verification', '', 'post');
  if ($hash != md5($capt)) {
    return "You have entered an incorrect verification code.";
  }
}
?>

Also make sure to enable the serverside validation.

/Fredrik
This topic is locked and no more replies can be posted.