3
Contributors
2
Replies
20
Views
2 Weeks
Discussion Span
Last Post by gabrielcastillo
0

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.

0

You can complete this task with typeahead.js library.

Bootstrap Typeahead

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

$('input#email_seach').typeahead({
    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.
      $('input[name="email_id"]').val(item.value);
    }
  });

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.