how to get value for search in joomla module

Joomla Asked by Rhea Lorraine on September 5, 2021

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 } ?>

One Answer

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('');

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(' = ' . (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.

Answered by Irata on September 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP