1

I've been looking all over, but I can't find a specific case on this. I'm writing a plugin for a open-source software program, and am using it's $form class and functions to render my forms without needing to manually insert in HTML.

I'm trying to make a Minimum Age (#) and Maximum Age (#) selectbox fields, each ranging from 1 to 100. I know something like this can be quickly done with something like

for ($i = 1; $i <= 99; $i++)

And then apply $i to a form in your webpage. But since this is a MVC program, I am bounded (for the most part) to what classes, objects and functions are available. When making a selectbox's actual options in this program, you typically do something like:

$field->setOptions(array(
   "Value"=>"Text Label",

rinse and repeat. However, since I'm trying to make a large list of numbers, I've been trying to find a way to somehow use range() or maybe array_push in place. I've tried the following thus far:

    function forAge(){
    for ($i = 1; $i <= 99; $i++){
        $array[] = $i;
    }}

    $tminage->setOptions(array(
        $array[]=>$array[]));

Or trying to pass the straightup "for" method and "range" method as the array's value. None of them work, either returning errors or displaying nothing on the selectbox. I'd like to know if there's any good way of working around this, or if it's a no-go because of the specific function wanting a simple array with a value and a label.

  • What is the open source framework you're using? If you edit your question to add that, and add its tag, then someone using it might answer. In our home-grown system we use template files where we can replace "%%-fragement-name-%%" with any block of HTML that we want. – Dave S Jul 09 '18 at 02:20
  • It's Oxwall, but I think it's support on stack is relatively small. It uses SMARTY for templating with variables, and I was thinking I can maybe apply some sort of dummy value and then apply the actual method to the template instead. – Jake Brunton Jul 09 '18 at 02:23

1 Answers1

2

Maybe i am missing something here but there is what I would do :

$minAgeOptions = array();
for ($i = 1; $i <= 100; $i++){
    $minAgeOptions[$i] = $i;
}

$tminage->setOptions($minAgeOptions);