KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Trouble getting value from Select #1853

Closed Richb201 opened this topic on on Jan 20, 2021 - 3 comments

Richb201 commented on Jan 20, 2021

I am having an issue with generating the report in the view file. Prior running the view, I have loaded up an array(TY) and a last_TY and put them in the session variables. Now I am in the view and here is the code:

<?php
echo "<br><br><br><br><br><br><h3>Report for:  ".$_SESSION['campaign']." for tax year ended ".$_SESSION['last_TY'];
?>
<form method="post">
    <?php
    $taxyear=$_SESSION['last_TY'];
\koolreport\inputs\Select::create(array(
    "name"=>"taxyear",
    "data"=>$_SESSION['TY'],  //this is a list of years in an array
    "defaultOption"=>array($taxyear=>''),
));
    ?>
    <button type="submit">Submit</button>
</form>

<?php
if (isset($_POST['taxyear']))
    $_SESSION['last_TY']=$_POST['taxyear'];
?>

The problem is that when a user picks a taxyear from the Select, and then pressed Submit, the echo is not working. Instead is is showing the PREVIOUS tax year. The only way to get <?php echo "<br><br><br><br><br><br><h3>Report for: ".$_SESSION['campaign']." for tax year ended ".$_SESSION['last_TY']; ?> to run with the proper value, is to press select again.

KoolReport commented on Jan 20, 2021

You put the last code on top like this

<?php
if (isset($_POST['taxyear']))
    $_SESSION['last_TY']=$_POST['taxyear'];
?>

<?php
echo "<br><br><br><br><br><br><h3>Report for:  ".$_SESSION['campaign']." for tax year ended ".$_SESSION['last_TY'];
?>
...
Richb201 commented on Jan 21, 2021

That worked great. Thx. Let me confirm what I am seeing: When report->run->render() is run the following modules run: a) the report -creation of datastores b) the report view - creation of Table or Charts or whatever

when I modify the date (via Select) and press 'submit', only b is running. (a) does not run again.

For me this means that I better not include a WHERE in (a) that is dependent on the date modified in (b), since it is not running again!

In addition, I have the following in my view file


Table::create(array(
    "dataStore"=>$this->dataStore("ThreeWayRiskAnalysis"),
    "showFooter"=>true,
    "columns"=>array(
        "employee",
        "title",
        "wages"=>array(
                "cssStyle"=>"text-align:right",
                "prefix"=>"$",
                "footer"=>"sum",
                "footerText"=>"<b>Total Wages:</b> @value"
            ),
        "risk",
        "QREs"=>array(
            "cssStyle"=>"text-align:right",
            "prefix"=>"$",
            "footer"=>"sum",
            "footerText"=>"<b>Total Wages Qualified:</b> @value"
        )
    ),
    "cssClass"=>array(
        "table"=>"table-bordered table-striped table-hover"
    )
));


Can I filter this (to a specific taxyear) within this statement? I know how to create a filter when building the datastore (in a).

KoolReport commented on Jan 21, 2021

No it does not. Both (a) and (b) runs.

$report->run()->render();

The run() will prepare dataStores, and the render() will trigger the view to be rendered with data prepared from run().

You can use the $_POST["taxyear"] in setup() function to change your query if any.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
solved

None