Tag Archives: Basic

Your First Autcomplete

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");

All PHP Autocomplete code will require minimum two lines of PHP code.

$pac = new C_PhpAutocomplete('company');
$pac -> display('SELECT');
  • The first line is to create our PHP Autocomplete object by calling the constructor;
    • the 1st parameter is the unique ID to an existing Select tag
  • The second line is to call display method to render control on the screen.

The complete code:

<?php
require_once("../conf.php");
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP Autocomplete Intro</title>
</head>
<body>
   
<?php
$pac = new C_PhpAutocomplete('company');
$pac -> display();
?>

<select id="company">
    <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>

</body>
</html>

Result:
PHP Autocomplete supports searching and filtering out of the box.