KoolReport's Forum

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

Checkbox List Error #295

Open Jeff Baker opened this topic on on May 25, 2018 - 7 comments

Jeff Baker commented on May 25, 2018

Getting this:

Warning: in_array() expects parameter 2 to be array, string given in C:\Program Files (x86)\Ampps\www\koolreport\packages\inputs\CheckBoxList.tpl.php on line 9

With this code:

<?php
		CheckBoxList::create(array(
			"name"=>"IsMVP",
			"data"=>array(
				"Yes"=>"Y",
				"No"=>"N",
			)
		));
		?>

Not sure what is going on, the documentation for this item is pretty messy. Also is there no simple checkbox input control?

KoolReport commented on May 25, 2018

I think the value that you assign to CheckBoxList is not in array, for example some where you will define:

"IsMVP"=>"Y"

It should be in array "isMVP"=>array("Y")

It seems to me that you want only single checkbox for "Y" or "N" so just add only 1 option for CheckBoxList:

<?php
CheckBoxList::create(array(
    "name"=>"IsMVP",
    "data"=>array(
        "Yes"=>"Y",
    )
));
?>

Jeff Baker commented on May 29, 2018

Not sure I understand your answer... It looks exactly the same as what I provided. Also tried "Yes"=>array("Y") but this did not work. EDIT: I had to cast the name to an array. Also I need the VALUE of the checkbox to be "N" if not checked and "Y" if checked. Can I do this with a single checkbox?

KoolReport commented on May 29, 2018

You do this:

In the report controller:

class MyReport
{
    use \koolreport\inputs\Bindable;
    use \koolreport\inputs\POSTBinding;
    protected function defaultParamValues()
    {
        return array(
            "IsMVP"=>array('Y'),
        );
    }

    protected function bindParamsToInputs()
    {
        return array(
            "IsMVP"
        );
    }    
    ...

}

And in the view:

<?php
CheckBoxList::create(array(
    "name"=>"IsMVP",
    "data"=>array(
        "Yes"=>"Y",
    )
));
?>
Jeff Baker commented on May 29, 2018

This was actually the correct code...

<?php
CheckBoxList::create(array(
    "name"=>array("IsMVP"),
    "data"=>array(
	"Yes"=>"Y",
    )
));
?>

If I do a single item "Yes" => "Y" how does the control know the value should be "N" if it is not checked?

KoolReport commented on May 29, 2018

Hi, one thing I want to ask: Normally we use list of CheckBox when we have multiple options to choose. And for the "Yes" and "No", we should use RadioBox or single CheckBox. Why do you want to use CheckBoxList for "Yes" and "No" option because user can choose both yes and no?

Jeff Baker commented on May 29, 2018

I could not find a single location in the documentation that showed your single checkbox control. I could use a Radio, but I would love to just use a single checkbox.

KoolReport commented on May 29, 2018

Understand. So you do exactly like my above code (including the report controller class). You notice that I set the "IsMVP"=>array('Y') in the defaultParamValues() function. This will make the CheckBoxList select "Yes" as default. If you do not want to select "Yes" as default, you set "IsMVP"=>array() (empty array).

So you may wonder how do we know which option user selected. So basically, after user post the form, you can get value from $this->params["IsMVP"] as array. If user select "Yes", you will receive value array('Y'), if use don't select then you will get array(). You can check "Yes" or "No" simply with isset($this->params["IsMVP"][0])

Let me know if you need further explanation.

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
None yet

None