Docs – PHP Autocomplete https://phpautocomplete.com The Ultimate PHP Dropdown Mon, 28 Apr 2014 20:58:17 +0000 en-US hourly 1 https://wordpress.org/?v=7.0.4 System Requirements https://phpautocomplete.com/docs/system-requirements/ Tue, 11 Feb 2014 18:21:37 +0000 http://phpautocomplete.com/?p=100 PHP Autocomplete requires web server that supports PHP 5.3 and higher.

  • PHP 5.3 or later
  • Apache, Tomcat, or Microsoft IIS web server

PHP Autocomplete is prepackaged with required jQuery autocomplete Select2 Javascript libraries and server side components. Developers don’t have to download them separately. PHP Auto complete does not require a database to work.

]]>
Installation https://phpautocomplete.com/docs/installation/ Tue, 11 Feb 2014 18:24:30 +0000 http://phpautocomplete.com/?p=101 First and foremost, download the PHP Autocomplete from the download page, and then extract the zip file in your web server root folder.

In conf.php, simply set PAC_PATH representing the relative or absolute URL to the PHP Autocomplete library.

Assuming phpAutocomplete folder is inside the web root:

define('PAC_PATH','/phpAutocomplete/');

Then include conf.php in on top of the every page.

require_once("../conf.php");
]]>
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" />
]]>
add_event() https://phpautocomplete.com/docs/add_event/ Tue, 11 Feb 2014 18:57:32 +0000 http://phpautocomplete.com/?p=104 Add event handler. A typical use of this method is to pass Select2 event name, then a Javascript event handler function. Note that the generated Javascript methods is injected BEFORE end of $(document).ready(…)

Signature:

public function add_event(param1, param2, ....)

Parameter:

  • variable-length argument lists

A list of supported events:

  • change
  • select2-opening
  • select2-open
  • select2-close
  • select2-highlight
  • select2-selecting
  • select2-removing
  • select2-removed
  • select2-loaded
  • select2-focus
  • select2-blur
  • select2-clearing

Example:

$pac -> add_event('select2-close', 'function() { console.log("close"); }');
]]>
disable_search() https://phpautocomplete.com/docs/disable_search/ Tue, 11 Feb 2014 19:05:08 +0000 http://phpautocomplete.com/?p=108 Disable search. This essentially removes the search from the dropdown. Disable search makes the control looks like a regular dropdown.

Note that when either set_max_input_length() or set_min_input_length() method is presented, disable_search() is ignored.

Signature:

public function disable_search()
]]>
display() https://phpautocomplete.com/docs/display/ Tue, 11 Feb 2014 19:10:12 +0000 http://phpautocomplete.com/?p=109 Display the auto-complete control finally. When attached to <select>, set $tag to SELECT, or INPUT when attached to <input type=”hidden”>.This should be the LAST method to call.

Signature:

public function display(string $tag = 'INPUT', bool $script_include = true)

Parameters:

  • $tag: “SELECT” or “INPUT” (default to “INPUT”, case sensitive)
  • $script_include: true or false indicates whether to include required jQuery autocomplete JavaScript libraries (default to true).
]]>
enable_closeonselect() https://phpautocomplete.com/docs/enable_closeonselect/ Tue, 11 Feb 2014 21:29:36 +0000 http://phpautocomplete.com/?p=114 Whether to collapse the dropdown after a selection is made. Allows rapid selection in multi-select mode. Only applies in multi-select mode.

Signature:

public function enable_closeonselect(bool $closeOnSelect = true )

Parameters:

  • $closeOnSelect: Default to true
]]>
enable_combobox() https://phpautocomplete.com/docs/enable_combobox/ Tue, 11 Feb 2014 22:29:36 +0000 http://phpautocomplete.com/?p=115 Enable combobox. It is disabled by default. By default, PHP Autocomplete only allows value from existing options in the dropdown. When combobox is enabled, new value can be added to the selection.

Signature:

public function enable_combobox(bool $enable = true )

Parameters:

  • $enable: true or false
]]>
enable_readonly() https://phpautocomplete.com/docs/enable_readonly/ Thu, 13 Feb 2014 13:23:01 +0000 http://phpautocomplete.com/?p=124 Set the auto complete control to be read only.

Signature:

public function enable_readonly(bool $readonly = false )

Parameters:

  • $readonly: true or false
]]>
set_child() https://phpautocomplete.com/docs/set_child/ Thu, 13 Feb 2014 14:04:34 +0000 http://phpautocomplete.com/?p=138 Set cascading/dependent/nested drop-down. See online example for more details.

Signature:

public function set_child(C_PhpAutocomplete $pac_obj, JavaScript $child_js_dataname )

Parameters:

  • $pac_obj: object
  • $child_js_dataname: variable name that references to data array
]]>