# Search on index action on cakephp 4.2

**URL:** <https://discourse.cakephp.org/t/search-on-index-action-on-cakephp-4-2/9142>\
**Category:** Uncategorized\
**Created:** [March 20, 2021, 12:04am UTC](https://discourse.cakephp.org/t/search-on-index-action-on-cakephp-4-2/9142 "2021-03-20T00:04:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdeanquin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/mdeanquin/32/1802_2.png) [@mdeanquin](https://discourse.cakephp.org/u/mdeanquin)\
**Post date:** [March 20, 2021, 12:04am UTC](https://discourse.cakephp.org/t/search-on-index-action-on-cakephp-4-2/9142/1 "2021-03-20T00:04:19Z")

</div>

I implemented a search in index action, but when I click on the search button throws me this exception:

 ![search](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/0/08cb6afb2ad506956de5e03852bfb14709f93082.png)  
This is the code to search in index view:

```auto
<?php
    echo $this->Form->create(null, ['valueSources' => 'query']);
    echo $this->Form->control('search', ['label' => 'Buscar', 'placeholder' => 'Wildcards: * and ?']);
    echo $this->Form->control('profile_id', ['label' => 'Perfil', 'empty' => '- Seleccione un perfil -', 'options' => $profiles]);
    echo $this->Form->button(__('Buscar'), ['class' => 'btn btn-primary']);
     if (!empty($_isSearch)) {
        echo ' ';
	echo $this->Html->link(__('Reset'), ['action' => 'index', '?' => array_intersect_key($this->request->getQuery(), array_flip(['sort', 'direction']))], ['class' => 'btn btn-default']);
    }
    echo $this->Form->end();
?>

```

And this is the code to enable search in UsersTable.php:

```auto
		$this->addBehavior('Search.Search');

		$this->searchManager()
			->value('username')
			->value('email')
			->value('profile_id')
			->add('search', 'Search.Like', [ 
				'before' => true,
				'after' => true,
				'fieldMode' => 'OR',
				'comparison' => 'LIKE',
				'wildcardAny' => '*',
				'wildcardOne' => '?',
				'fields' => ['username','email','profile_id'],
			]);

```

How can I solve this issue?

---

<div class="post-metadata">

**Author:** ![ADmad](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/admad/32/20_2.png) [@ADmad](https://discourse.cakephp.org/u/ADmad)\
**Post date:** [March 22, 2021, 2:17pm UTC](https://discourse.cakephp.org/t/search-on-index-action-on-cakephp-4-2/9142/2 "2021-03-22T14:17:46Z")

</div>

You have added `profile_id` to list of fields to search for “Like”. That’s what’s causing the problem since the search value is a string while `profile_id` is a integer field.
