how to get value for search in joomla module.

Does anyone know how to get the value for the search field? my problem is that after i search for specific data it still shows everything

In my helper.php I have this code. but doesn't work

    public function getFilterForm()
        JHtml::_('formbehavior.chosen', 'select');

        Form::addFormPath(dirname(__FILE__) . '/forms');

        $form = Form::getInstance('module.filter', 'filter');

        return $form;

        public function getFieldsvalue($params)
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);


        $rows = $db->loadObjectList();

        return $rows;

    public function loadFormData()
        $data = $rows->getFieldsvalue();

        return $data;

I have a folder forms and inside it has filter.xml

in the tmpl folder. the in the default.php this is my code

<form name="adminForm" id="adminForm">
    <?php echo JLayoutHelper::render('joomla.searchtools.default', array ('view' => (object) array ('filterForm' => $form))); ?>

    <table class="table table-striped">
  <thead class="thead-light">
      <th scope="col">#</th>
      <th scope="col">Name</th>
      <?php foreach  ($rows as $item) {?>
      <th scope="row"><?php echo $item->id; ?></th>
      <td><?php echo $item->name; ?></td>
      <?php } ?>

  • 1
    Are you trying to filter the data from #__users table or are you tryng to get the filter value from #__user? It is not really clear what your code is trying to do. Maybe if you provide more explanation of what you are trying to achieve would help. Update your post with the contents of the filter .xml you mention in your /forms folder and the name of the table with the data you are trying to filter.
    – Irata
    Oct 19, 2019 at 11:34
  • in the view.. if i enter data on search field, how to get the data in the helpers.php? because i want to use it for my Where clause sql Oct 19, 2019 at 11:54
  • @RheaLorraine Please return to this page. Abandoned pages are not good for researchers or volunteers that try to help you. Pleas see if you can progress this page toward a resolution. Nov 12, 2020 at 19:59

1 Answer 1


The basics of what you need are in your filter .xml file there is a name= field and that is where the text you want to filter your list will be stored. In the below example it is 'search.

<?xml version="1.0" encoding="utf-8"?>
    <fields name="filter">
        <field name="search" type="text" hint="COM_INVENTORY_SEARCH_FILTER_SUBMIT"

Because haven't answered my earlier question about if you are trying to filter the #__user table I can't be more specific other than to say normally your data base call would or should be be in a model and not a helper. This would extend JModelList that has a few auto-magical things happening in the background to help to wen dealing with data and tables.

Either way in your function to query the table you need to have something like this line to retrieve the value from the search field from the User State object where it should have been stored from your form. // Filter by search $search = $this->getState('filter.search');

And then you need to build add the Where clause to the query with something like this

if (!empty($search))
    if (stripos($search, 'id:') === 0)
        $query->where('a.id = ' . (int)substr($search, 3));
        $search = $db->quote('%' . $db->escape($search, true) . '%');
            'a.ItemCode LIKE ' . $search,
            'a.GenericCode LIKE ' . $search,
            'a.Description LIKE ' . $search,
            'a.SupplierName LIKE ' . $search,
        ], 'OR');

There is not enough of your code or an explanation to tell if your Form is correctly passing your value from the Filter/search box to the userState object, but this might be enough information above to help you progress.

  • $search = $this->getState('filter.search');... this works in component. but in module it doesnt work. Oct 19, 2019 at 12:27
  • Without more details, and example or a link to what you have got then I have to keep guessing. You could create an input field on your form to receive a value for the filter and then once the form is submitted then access $_POST['input'] to get the field and put that field into your Where clause.
    – Irata
    Oct 19, 2019 at 12:47
  • As another example, mod_login uses this code in the com_user/controllers/user.php to retrieve the username and password fields when you login, $app = JFactory::getApplication(); $input = $app->input->getInputForRequestMethod();
    – Irata
    Oct 19, 2019 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.