Skip to content

Instantly share code, notes, and snippets.

@abdullahbutt
Last active December 27, 2015 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdullahbutt/7403147 to your computer and use it in GitHub Desktop.
Save abdullahbutt/7403147 to your computer and use it in GitHub Desktop.
CI form dropdown
Now let's imagine that you are writing a data entry form in HTML, and you want
a drop-down query box. Let's say this drop-down query box shows three options and allows the user to select one of them. In HTML, a drop-down box can be created like this:
<select name="type">
<option value="1">www.this.com</option>
<option value="2">www.that.com</option>
<option value="3" selected>www.theother.com</option>
</select>
CI's version is both shorter and, because it works from an array, more adapted to PHP processing:
$urlarray = array(
'1' => 'www.this.com',
'2' => 'www.that.com',
'3' => 'www.theother.com',
);
$variable .= form_dropdown('url', $urlarray, '1');
As $variable is not defined, we can echo it as below:
echo form_dropdown('url', $urlarray, '1');
In HTML, you need to type 154 characters; in CI, 128.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment