Note that there are some explanatory texts on larger screens.

plurals
  1. PODrupal custom form and autocomplete issue
    primarykey
    data
    text
    <p>Some how I managed to get it work. But still the result is not coming along with the autocomplete.</p> <p>Posting my latest code now,</p> <p>the textfield code</p> <pre><code>$form['town'] = array( '#type' =&gt; 'textfield', '#required' =&gt; TRUE, '#autocomplete_path' =&gt; 'hfind/town/autocomplete', ); </code></pre> <p>menu function code</p> <pre><code>function hfind_menu() { $items = array(); $items['hfind/town/autocomplete'] = array ( 'title' =&gt; 'Autocomplete for cities', 'page callback' =&gt; 'hfind_town_autocomplete', 'access arguments' =&gt; array('use autocomplete'), 'type' =&gt; MENU_CALLBACK ); return $items; } </code></pre> <p>the callback function code</p> <pre><code>function hfind_town_autocomplete($string){ $matches = array(); $result = db_select('towns', 't') -&gt;fields('t', array('town_name')) -&gt;condition('town_name', '%' . db_like($string) . '%', 'LIKE') -&gt;execute(); foreach ($result as $row) { $matches[$row-&gt;city] = check_plain($row-&gt;city); } drupal_json_output($matches); } </code></pre> <p>I hope this may the final edit.</p> <p>The current situation is, autocomplete is working</p> <p>The url is hfind/town/autocomplete/mtw</p> <p>but it is not able to find any data from the database. I found why and unable to fix it. It is because in the last function I've added above the $string needs to be the 'search query' but it is always querying the database as 'autocomplete'. I mean the $string variable always having the value 'autocomplete' instead of user typed value.</p> <p>One more problem is, even after providing the permission to all types of user to access search autocomplete on the forms, guests users are not able to use the feature.</p> <p>Please please someone help me..</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload