4 Months
Discussion Span
Last Post by gabrielcastillo

I'm going to write "never do this." Why?

For your autocomplete to work, you would have to send over the list of email addresses to the user and that's a problem. Your site would them LEAK USER EMAIL ADDRESSES.

That won't be a good thing. For this round, let the browser do its thing on autocomplete.


You can complete this task with typeahead.js library.

Bootstrap Typeahead

<input id="email_search" type="text" name="email_search" value="">

    ajax: '/search_database_for_email.php'
    displayField: 'email',
    valueField: 'id',
    onSelect: function(item) {
    //This is used to populate a hidden field with the email id if returned.

On the backend, do a query to the database using a LIKE statement.

`SELECT * FROM email_list WHERE email LIKE %{filter_var($_POST["query"],FILTER_SANITIZE_STRING)}%`

Send your query results back as JSON object.

Warning: This code is not tested.. This is just to give you a starting point.

Edited by gabrielcastillo: mis spelled word

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.