2

So my predicament is that I am using Joomla, and inside of my articles I am using the Sourcerer plug-in so I can use PHP inside of my articles. So far everything has been pretty simple--I post form data to a PHP script and the queries are executive. Nothing special.

However; I would like to post data from one Joomla article, and get that data in another. Ie. Select a user in a form in one article, post that data, redirect to another article, and get the previously posted data and put the information in a table.

It doesn't need to be an article--even a custom HTML or 3rd party module would work; but so far I haven't had much luck in the way of finding something suitable. I'm just trying to avoid having a completely separate page for this thing, and I'd like to keep the layout of the website as uniform as possible.

  • You would be best off using a session for this – Lodder Nov 12 '15 at 16:30
3

To get form data in Joomla you can use:

$jinput = JFactory::getApplication()->input;

To get a value from JInput, you can use:

$foo = $jinput->get('varname', 'default_value', 'filter');

Check below url for more detail:
https://docs.joomla.org/Retrieving_request_data_using_JInput

2

It would be better to post code than link to an external reference. I tried to reply to XWS's post but its hard to add formatted code there, hence my own post. So to use JSession to set a variable:

$foo = 'bar';
$session = JFactory::getSession();
$session->set('path.to.my.variable', $foo);

// Retrieve the stored value (could be a different file on a different page request)
$foo = $session->get('path.to.my.variable');
echo $foo; // outputs 'bar'

Note that by using a dotted name path, you are actually creating a nested array in PHP's global $_SESSION. This comes in handy when you want to set an array as a session variable:

$foo = array('foo' => 'bar', 'foofoo' => array('me' => 'you'));
$session = JFactory::getSession();
$session->set('path.to.my.variable', $foo);

echo $session->get('path.to.my.variable.foo'); // outputs 'bar'
echo $session->get('path.to.my.variable.foofoo.me'); // outputs 'you'

The above examples uses the default session namespace, you can alternatively use your own namespace, in the example below I'm using 'myNameSpace' as the namespace name:

$foo = 'bar';
$session = JFactory::getSession();
$session->set('path.to.my.variable', $foo, 'myNameSpace');

// Retrieve
$foo = $session->get('path.to.my.variable', 'default', 'myNameSpace');
echo $foo; // outputs 'bar'

Finally moomoochoo suggested using memcache as an altenative. I've not seen any issues with JSession, but be aware that the JSession class wraps several different storage options, the default is to store to the mySQL database, but you also have apc, memcache, wincache, and xcache drivers available. So if you did have something like memcache installed this could be selected as a JSession storage option in Joomla's global config page, system tab 'session handler' dropdown option.

1

Use Sessions Vars. As Sourcerer allows you to run PHP withinside an article see:

https://docs.joomla.org/JFactory/getSession

You can set the session, for the current user. Store the variable and then on return to the new page get it if it exists.

1

As lodder and XWS have already said, Joomla sessions will do what you want. I've had a lot of problems with Joomla sessions, so I'm gonna suggest some alternatives. You could use Redis or Memcached (or something similar) to store and retrieve values using PHP. These are server side solutions rather than Joomla based and are probably overkill for what you want.

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.