What is the best library to create a text box with an automatic AJAX suggestion in web form?

I am creating a web application for work where the user must enter the name of the person who requested the job. I would like to create a simple AJAX drop-down menu with automatic suggestion, so they don’t need to enter the whole name. On the backend, the database will contain offers based on previous entries. Website built using CakePHP 1.1.

I know that there are many libraries, some better than others. Which, in your opinion, is the fastest and easiest to implement?

+6
javascript ajax php
source share
3 answers

Since you are using CakePHP 1.1, I suggest you check out the part of the manual that deals with Helpers

If you go to "AJAX", you will see that you can do something like this in your controller:

function autocomplete () { $this->set('people', $this->Person->findAll("name LIKE '%{$this->data['Person']['name']}%'") ); $this->layout = "ajax"; } 

And in your autocomplete.thtml you will have:

 <ul> <?php foreach($people as $person): ?> <li><?php echo $person['Person']['name']; ?></li> <?php endforeach; ?> </ul> 

To create an autocomplete field in another view, follow these steps:

 <form action="/people/index" method="POST"> <?php echo $ajax->autoComplete('Person/name', '/people/autocomplete/')?> <?php echo $html->submit('View Person')?> </form> 

To do this, you need to have "Ajax" in your helpers array and include the Prototype / script.aculo.us libraries.

Good luck.

+5
source share

I had great success with the Brand Spanking New Implementation of Auto-Suggest. It also contains PHP examples.

+2
source share

You can't go wrong in jQuery. http://nodstrum.com/2007/09/19/autocompleter/

+1
source share

All Articles