Constructor – PHP Autocomplete https://phpautocomplete.com The Ultimate PHP Dropdown Tue, 11 Feb 2014 21:22:22 +0000 en-US hourly 1 https://wordpress.org/?v=7.0.4 Constructor https://phpautocomplete.com/docs/constructor/ Tue, 11 Feb 2014 18:39:36 +0000 http://phpautocomplete.com/?p=102 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" />
]]>