// Ensures that the specified array to hold form elements exists. // This function is needed because browser(s) only automaticaly creates an array // when there is more than one form element with the same name.
I had similar problem with one of my CGI scripts where I had to deal with multiple drop down and radio boxes. The way I was able to make sure that my CGI would always get an array of elements is by simply inserting a hidden form element with the same name. In addition, I also marked a single selection (in the select box) as default. For example, if you had a select field 'foo_choices', you'd need to add this hidden field:
So, when the form is submitted, you'll always have at least two instances of the 'foo_choices' parameter sent to your CGI. The CGI module, seeing this, will build an array. Frankly, I didn't have to resort to complex JS scripts to make this work.<form ... > <input type="hidden" name="foo_choices"> Make a foo choice: <select name="foo"> <option > ... <!--- leave one option pre-selected by default... ---> </select> </form>
$"=q;grep;;$,=q"grep";for(`find . -name ".saves*~"`){s;$/;;;/(.*-(\d+) +-.*)$/; $_=["ps -e -o pid | "," $2 | "," -v "," "];`@$_`?{print"+ $1"}:{print" +- $1"}&&`rm $1`; print$\;}
In reply to Re: CGI Ensure Array
by vladb
in thread CGI Ensure Array
by SteveRoe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |