KoolReport's Forum

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

Adding input to page, causes redirect to /[object%20Object] #2349

Closed Niall McGuirk opened this topic on on Sep 22, 2021 - 9 comments

Niall McGuirk commented on Sep 22, 2021

I'm trying to add some input filters to the report. However, when I add a Select2 input, and reload the page the page reloads to /[object%20Object] on the end, causing a 404. I can't access the actual page. However, I did successfully added an input connected to on of my fields, which didn't cause the error/redirect.

The error seems to only occur when I change the name to that of location, which is the new input I created in myreport.view and in defaultparamters() and bindtoInputs(). It is strange as, it previously did the same thing when trying to make the select input which, now exists in the report without problems. It just worked one time.

Here is the MyReport.php

<?php
//Step 1: Load KoolReport
require_once "../../load.koolreport.php";

//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    
    protected function settings()
    {
        $config = include "../../config.php";
        return array(
            "dataSources"=>$config
        );
    }
    
    protected function defaultParamValues()
    {
        $date=date_create("2021-07-16");
        date_add($date,date_interval_create_from_date_string("-42 days"));
        $sd = date_format($date,"Y-m-d");
        
        return array(
            "startDatePicker"=>date($sd . " 00:00:00"),
            "endDatePicker"=>date("Y-m-d 23:59:59"),
            "select"=>"",
            "location"=>"",
        );
    }
    //Binds report names to input controls eg. "years" = "years"=>"years",
    protected function bindParamsToInputs()
    {
        return array(
            "startDatePicker",
            "endDatePicker",
            "select",
            "location"
        );
    }
    
    protected function setup()
    {
        
        
        
        
        
        
        $this->src('dealhackdb')
        ->query('Select 
                 tbl_dealhack.id,
                 tbl_profile.user_id AS UserID,
                 hack_description AS Decription,
                 created_date AS "Created",
                 attachment_location AS "Attachment Location",
                 uploaded_date AS Uploaded ,
                 Company,
                 TribeName AS "Tribe Name"
                 From tbl_dealhack
                 left join tbl_dealhack_attachments on tbl_dealhack_attachments.dealhack_id = tbl_dealhack.id
                 left join tbl_profile on tbl_profile.user_id = tbl_dealhack.user_id
                 Left join tbl_attachment_type on tbl_attachment_type.id = tbl_dealhack_attachments.attachment_type_id
                 left join tbl_companytribe on tbl_companytribe.id = tbl_profile.TribeID
                 WHERE created_date BETWEEN :start AND :end
                 AND attachment_type_id = 4
                 
                 ;
')
            //-- AND TribeName LIKE :tribe
        ->params(array(
            ":start"=>$this->params["startDatePicker"],
             ":end"=>$this->params["endDatePicker"],
            //":tribe"=>$this->params["select"]
            ))
        ->pipe($this->dataStore("sales"));
        
        //Date( Transaction.Open_Date ) >= DATE_ADD(CurDate(), INTERVAL -6 WEEK)
    } 

}

Here is the MyReport.view.php

<?php
    use \koolreport\datagrid\DataTables;
    use \koolreport\inputs\DateTimePicker;
    use \koolreport\inputs\Select2;
?>
<div class="report-content">
    <div class="text-center">
        <h1>Deal Hack</h1>
        <p class="lead">
        Link Details
        </p>
    </div>
    
<!--    Filters for Page 3 (Stocktake)
Filter by location (first part of the URL) 
Filter by user/Tribe/Company
Filter by deal hack type
Filter by date
-->
    
    
<!--    DATE TO DATE FROM INPUT -->
    <form method="post">
        <div class="col-md-12 form-group">
            <strong>DateTimePicker</strong>
            <div class="row">
                <div class="col-md-6">
                    From Date:
                    <?php
                        DateTimePicker::create(array(
                            "name"=>"startDatePicker",
                            "maxDate"=>"@endDatePicker",
                            "format"=>"DD/MM/YYYY HH:mm",
                            "themeBase"=>"bs4",
                        ));
                    ?>
                </div>
                <div class="col-md-6">
                    To Date:
                    <?php
                        DateTimePicker::create(array(
                            "name"=>"endDatePicker",
                            "minDate"=>"@startDatePicker",
                            "format"=>"DD/MM/YYYY HH:mm",
                            "themeBase"=>"bs4",
                        ));
                    ?>
                </div>
           </div>
                    <div class="row">
<!-- TRIBE FILTER FROM INPUT-->
                       <div class="col-md-6">
                       Tribe:
                        <?php
                            Select2::create(array(
                                    "name"=>"select",
                                    "dataStore"=>$this->dataStore("sales"),
                                    "dataBind"=>"Tribe Name",
                                    "attributes"=>array(
                                        "class"=>"form-control",
                                    )
                                ));

                        ?>

                        </div>
                        <div class="col-md-6">
                       URL Location:
                        <?php
                            Select2::create(array(
                                    //***if i change this select to location, it causes the redirect error***
                                    "name"=>"select",
                                    "dataStore"=>$this->dataStore("sales"),
                                    "dataBind"=>"Tribe Name",
                                    "attributes"=>array(
                                        "class"=>"form-control",
                                    )
                                ));

                        ?>

                        </div>


                    </div>
                
        </div>
        <div class="form-group text-center " style="margin-top:30px;" >
            <button class="btn btn-lg btn-primary">Submit form</button>
        </div>
    </form>
    
    <?php
    DataTables::create(array(
        "dataSource"=>$this->dataStore("sales"),
        "options"=>array(
            "paging"=>true),
        "themeBase"=>"bs4", // Optional option to work with Bootsrap 4
        "cssClass"=>array(
            "table"=>"table table-striped table-bordered "
        )
    ));
    ?>
</div>
KoolReport commented on Sep 22, 2021

Please change name of control to be more unique, avoiding common name, let try

"name"=>"tribeSelector"
"name"=>"locationSelector"
Niall McGuirk commented on Sep 22, 2021

Should I change the name of the variable in BIndtoInputs and defaultparameters, too?

KoolReport commented on Sep 22, 2021

You can do:

    protected function bindParamsToInputs()
    {
        return array(
            "startDatePicker"=>"startDatePicker",
            "endDatePicker"=>"endDatePicker",
            "select"=>"tribeSelector",
            "location"=>"locationSelector"
        );
    }

This is the map, the left is report parameter name and the right is the input control name.

Niall McGuirk commented on Sep 22, 2021

I've changed it, which seems to have resolved the redirect error. However, it doesn't show the field in the input box.

I've put the name of the field from the sql query, into the dataBind variable, but it doesn't show, as it does for the other select box. I've tried to use the attachment_location, as well as Attachment Location, but neither resolve the error.

                        <div class="col-md-6">
                       URL Location:
                        <?php
                            Select2::create(array(
                                    //if i change this select to location, it causes the redirect error
                                    "name"=>"locationSelector",
                                    "dataStore"=>$this->dataStore("sales"),
                                    "dataBind"=>"attachment_location",
                                    "attributes"=>array(
                                        "class"=>"form-control",
                                    )
                                ));

                        ?>

                        </div>

KoolReport commented on Sep 22, 2021

Please remove the [object...] in your url

Niall McGuirk commented on Sep 22, 2021

Sorry, I uploaded the wrong screenshot. I've added the right one above.

KoolReport commented on Sep 22, 2021

It seems column "attachment_location" is not correct. Please check the name.

Niall McGuirk commented on Sep 22, 2021

I tried it again, it has now worked. Thanks for the help, and quick reply.

KoolReport commented on Sep 22, 2021

That's great to hear. You are welcome :)

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
help needed
solved

Inputs