title: Autocomplete widget in CakePHP 3.X
body: <p>I'm trying to implement a form for students to signup in my website with an autocomplete control for <em>Schools</em>. For this purpose, I went to the <strong>CakePHP 3.0</strong> reference and found a <a href="http://book.cakephp.org/3.0/en/views/helpers/form.html#creating-form-inputs" rel="nofollow noreferrer">tutorial to achieve this</a>. My problem is that they don't explicitly say how to retrieve the data (in this case the array of school names) for the autocomplete and for that reason I can't make it work.
  Here's my code:</p>
  
  <p>register.ctp</p>
  
  <pre><code>&lt;h1&gt;Registration&lt;/h1&gt;&lt;br&gt;
  &lt;?php echo $this-&gt;Form-&gt;create('User', array('action' =&gt; 'register', 'context' =&gt; ['validator' =&gt; 'registerValidator'], 'templates' =&gt; ['autocomplete' =&gt; '&lt;input id="school" name="{{name}}"{{attrs}}&gt;'])); ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;input('fname', array('label' =&gt; 'First Name *', 'required' =&gt; true, 'placeholder' =&gt; 'First Name')); ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;input('sname', array('label' =&gt; 'Last Name *', 'required' =&gt; true, 'placeholder' =&gt; 'Last Name')); ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;input('country', array('options' =&gt; array('Select...', 'India', 'USA', 'Canada'), 'placeholder' =&gt; 'Select')); ?&gt;
  &lt;?php //echo $this-&gt;Form-&gt;input('school', array('label' =&gt; 'School *', 'options' =&gt; array('Select...', 'School A', 'School B', 'School C'))); ?&gt;
  &lt;?php
  $this-&gt;Form-&gt;addWidget(
          'autocomplete', ['Autocomplete', 'App\View\Widget\Autocomplete']
  );
  $options = array("Arena", "Bambu", "Canela", "Perlita");
  //echo $this-&gt;Form-&gt;input('School', ['type' =&gt; 'autocomplete']);
  echo $this-&gt;Form-&gt;input('search', ['type' =&gt; 'autocomplete', 'label' =&gt; 'School *', 'id' =&gt; 'school', 'required' =&gt; true, 'autocomplete' =&gt; 'off', 'placeholder' =&gt; 'School']);
  //echo $this-&gt;Form-&gt;autocomplete('search', $options);
  ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;input('province_region', array('label' =&gt; 'Province/Region', 'placeholder' =&gt; 'Province/Region')); ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;input('city_town', array('label' =&gt; 'City/Town', 'placeholder' =&gt; 'City/Town')); ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;input('email', array('label' =&gt; 'E-mail *', 'required' =&gt; true, 'placeholder' =&gt; 'Email')); ?&gt;
  &lt;?php echo $this-&gt;Form-&gt;input('birth_dt', ['type' =&gt; 'date', 'label' =&gt; 'Date of birth *', 'minYear' =&gt; date('Y') - 100, 'maxYear' =&gt; date('Y'), 'empty' =&gt; '-', 'default' =&gt; '', 'required' =&gt; true]);
  ?&gt;
  
  &lt;?php echo $this-&gt;Form-&gt;input('password', array('label' =&gt; 'Password *', 'required' =&gt; true, 'placeholder' =&gt; 'Password')); ?&gt;
  
  &lt;?php
  echo $this-&gt;Form-&gt;input('pwd_repeat', array('label' =&gt; 'Confirm Password *', 'type' =&gt; 'password', 'required' =&gt; true, 'placeholder' =&gt; 'Repeat Password'));
  echo $this-&gt;Form-&gt;submit('Send');
  ?&gt;
  </code></pre>
  
  <p>Autocomplete.php
         
  
  <pre><code>   namespace App\View\Widget;
  
     use Cake\View\Widget\WidgetInterface;
     use Cake\View\Form\ContextInterface;
  
     class Autocomplete implements WidgetInterface {
  
  protected $_templates;
  
  public function __construct($templates) {
      $this-&gt;_templates = $templates;
  }
  
  
  
  public function render(array $data, ContextInterface $context) {
      $data += [
          'name' =&gt; '',
      ];
      return $this-&gt;_templates-&gt;format('autocomplete', [
                  'name' =&gt; $data['name'],
                  'attrs' =&gt; $this-&gt;_templates-&gt;formatAttributes($data, ['name'])
      ]);
  }
  
  public function secureFields(array $data) {
      // return [];
      return [$data['name']];
  }
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>UsersController.php</p>
  
  <pre><code>&lt;?php
  
  
  
  namespace App\Controller;
  
  use App\Controller\AppController;
  use Cake\ORM\TableRegistry;
  use Cake\Mailer\Email;
  use Cake\Routing\Router;
  use Cake\Event\Event;
  use Cake\Validation\Validator;
  
  class UsersController extends AppController {
  
  public $helpers = [
      'Form' =&gt; [
          'widgets' =&gt; [
              'autocomplete' =&gt; ['App\View\Widget\Autocomplete']
          ]
      ]
  ];
  ....
  </code></pre>
  
  <p>And here's the output:</p>
  
  <p><a href="https://i.stack.imgur.com/gs10T.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gs10T.png" alt="Can&#39;t make it work!"></a></p>
  
  <p>Any type of help will be extremely appreciated. Thanks in advance for helping.</p>