PHP Autocomplete constructor takes two parameters and must attach to an existing HTML <select> tag, or a <input type=”hidden”>.
When attached to <input type=”hidden”>, use the second parameter to load from a data array.
Signature:
public function __constructor
(string
$sel_id, array $data )
Parameters:
- $sel_id: The id attribute of either <select> or <input type=”hidden”> tag
- $data: Initial data to load the dropdown (Hidden Input only)
Remark:
- The $sel_id must have a corresponding <select> or <input type=”hidden”> tag with the exact same id.
- The $sel_id must be unique
Example 1 (when attached to a <select> tag):
<?php
$pac = new C_PhpAutocomplete('foobar');
$pac -> display('SELECT');
?>
<select id="foobar" multiple>
<option></option>
<option id="1">Apple</option>
<option id="2">Google</option>
<option id="3">Microsoft</option>
<option id="4">Facebook</option>
<option id="5">Twitter</option>
</select>
Example 2 (when attached to a <input type=”hidden”> tag):
<?php
$data = array(array('id'=>1, 'text'=>'Apple'),
array('id'=>2, 'text'=>'Google'),
array('id'=>3, 'text'=>'Microsoft'),
array('id'=>4, 'text'=>'Facebook'),
array('id'=>5, 'text'=>'Twitter'));
$pac = new C_PhpAutocomplete
('foobar');
$pac -> display('INPUT');
?>
<input id
="foobar" type
="hidden" />