3

I'm using JSession (in Joomla 3.9.x) to implement sort of a captcha field in a form, apparently the captcha code is been saved correctly in the session but I can't find the way to retrieve it, and when I'm trying to find how to use it in the Joomla Documentation, I got to API archived pages (what does "archived" mean?, that they are from older Joomla version?, then how / where do I search for the current version documentation?).

This is the file structure I'm using:

| - views/
| - | - form/
| - | - captcha/

... then in the form (./views/form/tmpl/default.php) I'm calling the captcha in this way:

<img src="<?php echo JURI::root(); ?>index.php?option=my_component&view=captcha&format=raw" width="120" height="40" />

... in the display method of the captcha view (./views/captcha/view.raw.php), after generating the random code I'm saving it this way (following this answer):

$session = JFactory::getSession();
$session->clear('myCaptchaCode');
$session->set('myCaptchaCode', $myRandomGeneratedCode);

Then (here it comes!) when I'm testing my session variables in the form (./views/form/tmpl/default.php), just imagine I refresh the form twice, and when I echo:

  • the $_SESSION['myCaptchaCode'], it has the code generated in the previous page;
  • and neither the JFactory::getSession->get('myCaptchaCode') nor the JFactory::getSession->set('myCaptchaCode') has the actual (expected) code, both are empty!

What am I doing wrong, what I'm missing?

0

JFactory::getSession is a method (function). JFactory::getSession()->get('myCaptchaCode') should do what you expect.

1
  • This answer has been autoflagged by the system for its length. Can you perhaps expand on your insights by providing additional relevant insights or links to documentation? – mickmackusa Apr 28 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.