1

I've installed Forena Reports. It's basically working, but I have some questions (see bottom of post to get right to it).

What I want to accomplish is the following

I want an anonymous user of the module page to be able to export their recommendations as a CSV file with a link like 'download now' or something.

Here's the staging environment for the tool I'm talking about, so you can see how it works: http://staging.grantstation-pathfinder.com/pathfinder.

So, as you can see, here's what I have so far

I have a custom module that's a multi-step form. The module prints out each page of the form. The user selects one option on each page (3 pages total) and on the final page submits the form. The module then redirects the user to a 'recommendations' page (page 4 - modulename/recommendations) where some custom SQL prints out to the page recommended resources for that user based on their selections in the form.

The values the users select are saved in session variables.

Here's how those variables get stored as sessions in the form itself. (This is the second page of the form, but they are all basically the same.)

function pathfindertool_first_form($form, $form_state) {
 // .. some code, some other fields, directions, etc.
        '#default_value' => isset($values['role']) ? $values['role'] : NULL,
        '#options' => array(
        t('Grant Writer'),
        t('Nonprofit Administrator'),
        t('Nonprofit Founder'),
        t('Consultant'))
    );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Next'),
      );
      return $form;
    }

    /**
     * Submit handler for the first form.
     *
     * @see pathfindertool_first_form() above
     */
     function pathfindertool_first_form_submit($form, &$form_state) {
      $values = $form_state['values'];

      // Save values to the form storage, add the next step function callback
      $form_state['rebuild'] = TRUE; 
      $form_state['storage']['role'] = $values['role'];
      // submit code
    }

On the recommendations page I call SQL and use the session variables to determine which recommendations to display to users.

Here's how I set the session variables and redirect the users to the recommendation's page.

$form_state['storage']['topic'] = $values['topic'];
// set session variables to be used on recommendations page
$_SESSION['role'] = $form_state['storage']['role'];
$_SESSION['level'] = $form_state['storage']['level'];
$_SESSION['topic'] = $form_state['storage']['topic'];
// when user clicks 'submit' redirect them to recommendations page
$form_state['redirect'] = 'pathfinder/recommendations';

I successfully installed and configured the Forena module, and it displays my tabular data from the SQL file I created with the parameters I manually set. The CSV download works too. That's all fine.

How do I ensure the Forena modules uses the session variables set by the user in the multi-page form (and not my predefined parameters)?

0

1 Answer 1

3

I'm not (yet) sure about this one, because of the "session variables" that aren't clear enough to me (yet) ... Below are a few techniques (features) that you may want to consider to get it to work.

1. Using JavaScript and/or Skins

A possible solution "might" be to think of some technique you can implement via a JavaScript. And then make that JavaScript available via what in Forena is called "skins" (used for e.g. theming a report, like to enable the 'DataTables' plugin if you want, etc).

There are some "interesting" issues in the Forena issue queue with some great examples (ideas) of things you can do (add to Forena) via JavaScripts and/or Skins. HEre are a few of them:

2. Specifying Report Parameters as part of the URL

Report Parameters are similar to using arguments in Views. You can specify them as part of the URL, by first adding a ?-mark, followed by the name of the report parameter, a =-sign, and then the parameter value. So something like ?state=VA that you append to the report URL.

To see it at work in the demo site, try this example which uses ?state=VA (watch the URL of it also). Then change the end of the URL to something like ?state=IL, ?state=CA, etc. To be complete, you can also specify multiple parameters (+their values) in an URL.

So if you have a way to massage those session variables in a such string added to the URL, then the answer to your question is something like "pass them as report parameters via the URL".

3. Other approaches

If what is above won't work, then please add more details about those "session variabes" (so that I can refine/rework my answer accordingly).

And if we don't find a real answer, then its time to experience the "support" that comes with Forena, via its issue queue on D.O. ... After all, keep in mind that I'm only a co-maintainer of this module. When I'm stuck (or out of Forena-inspiration), I escalate such questions/issues to David (the module owner and creator or Forena).

17
  • thank you again. I might have to go that route. But before I do, I thought I'd give you that extra info. you requested. I edited my question above and added what I believe is the relevant code for setting the session variables. This code is all in the .module file and occurs BEFORE the user gets redirected to the recommendations page. Actually the last line of the 2nd code chunk above SENDS them to the recommendation page. But you can see how the session vars are set.
    – Sage
    Jul 16, 2015 at 22:12
  • ah, ok. My understanding is that session vars are stored on the server. Where is determined by the session.save_path configuration. Usually this is in /tmp. This is totally just a php thing and doesn't touch the database I don't believe. It seems like if we used forena we'd have to make users include their parameters manually, which isn't ideal in this situation since they've already defined their parameters once when they took the multi-page form. Unless there's a way for forena to read from the /tmp directory?
    – Sage
    Jul 17, 2015 at 4:18
  • yes, very interesting! let me play around with this and I'll get back to you when I have a chance (probably tomorrow) to experiment with this. It's promising though.
    – Sage
    Jul 17, 2015 at 4:59
  • ok, great, "your turn" again ... looks like we're coming close to answer ALL 3 (original) questions ... While reviewing this parms stuff, make sure to also digest the docu that comes with Forena related to "parameters". And if you can/want, consider creating a docu issue in the forena issue queue about missing pieces in the docu (like how to use them in URLs, as I detailed in my answer) ... Better still: submit a forena patch to enhance the relevant docu (you'd learn a lot about how to use Forena for creating HELP documentation also ... As I did when I started with it). Jul 17, 2015 at 8:52
  • Just curious if you made any progress on "playing" (without trying to rush you) ... PS: did you change your "user name"? Jul 20, 2015 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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