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::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
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);
$query->select('*')
->from('#__users');
$db->setQuery($query);
$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">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
</tr>
</thead>
<tbody>
<?php foreach ($rows as $item) {?>
<tr>
<th scope="row"><?php echo $item->id; ?></th>
<td><?php echo $item->name; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
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"?>
<form>
<fields name="filter">
<field name="search" type="text" hint="COM_INVENTORY_SEARCH_FILTER_SUBMIT"
label="COM_USERS_FILTER_SEARCH_DESC"
class="js-stools-search-string"
/>
</fields>
</form>
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));
}
else
{
$search = $db->quote('%' . $db->escape($search, true) . '%');
$query->where([
'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
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP