Error when using Form Helper and select function

Hi, folks.

I'm working on a custom external form that will return pages edited based on a selected user and range of dates. I've got the user selector field working and the from/to date fields working, but I get the following error when I try to include a field to set the number of results per page:

Warning: Invalid argument supplied for foreach() in C:\wamp\www\concrete\concrete\helpers\form.php on line 329

I pulled up the form helper php file and found that line 329 is in the select function. This is the code I am using in my external form that is generating the error:

<td><?php echo $form->label('num_results', '# Results')?></td>
<td><?php echo $form->select('num_results', $numResults)?></td>

And here is line 329 in the form helper:

foreach($optionValues as $k => $value)

Can someone tell me what I'm doing wrong?


View Replies:
srs04 replied on at Permalink Reply
I don't know if you solved your issue already or not, but came across your solution while I was having the same problem myself.

Here's the format for the select form helper:
$form->select($name, $options, $value, $tagAttributes)
Outputs a select menu. The $options argument is a PHP array. The keys of the array will be used as the select option values, while the array values will be displayed in the menu. The $value parameter controls the initially checked select element.

It looks like in your code you've left out the array of options that it needs.

Hope this still helps.

INTcommunications replied on at Permalink Reply
I wasted a full day trying to figure out form helpers especially the select - I think that if your not adding a dynamic option list in the select element than just harcode them in like in the Concrete Widget documentation.
$form->select(array(0 => '',1 => 'Fish',2 => 'Pork',5 => 'Fruit');, $categorySelection, $selectedKeyValue);

I posted a question about being confused and someone graciously explained all about the select ( getting the option list Array from db function )

exchangecore replied on at Permalink Reply
Well I dunno about how gracefully I did it, but it's there.

Campbell, I think that you may have a different problem entirely. My *guess* is that $optionValues is just not an array at that point.
Try running a var_dump on the $optionValues, you may have to check to make sure that it is not null, or that it isn't false or whatever it is actually returning. I suspect you have an error in your code before you even make it to your helper functions.