Search form not working

flyboeing 16 Oct, 2013
Hi all,

For my website I am creating a search form with multiple fields. These are text boxes, drop down menus and radiobuttons.

I am having problem getting the results displayed. When I search for a registration, I get all the registrations from my database as if no search criteria has applied.

This is what I have in the "preview" tab:
Search form not working image 1

This is what I have in the "Event" tab:
Search form not working image 2

As you can see I have in the On Submit a DBMRL with the following settings:
Basic
Table: movements_ewas
Request Param: var_success
Model ID: movements_ewas

Advanced
Load Data: Yes
WHERE statement:
'reg' LIKE '%<?php echo $form->data['reg']; ?>%' OR 'type' LIKE '%<?php echo $form->data['type']; ?>%' OR 'status' LIKE  '%<?php echo $form->data['status']; ?>%'


In the On Empty Result I have a custom code with a text if there are no records found and a 'show stopper' (got that one from the DBMRL tutorial).

The following custom code is loaded after the DBMRL:
<table>
<?php
foreach($form->data['movements_ewas'] as $search):
?>
</tr>
<td>Reg:<?php echo $search['reg']; ?></td>
<td>Type:<?php echo $search['type']; ?></td>
</tr>
<?php
endforeach;
?>
</table>


So when I am going to test my form I get all the reg and type from my database (in a list) and below that there is my debugger telling me the following thing:
Search form not working image 3

How can I get my search form to work?

Regards,
Ruud

PS. Using Joomla 2.5 and CFv4
RobP 16 Oct, 2013
Are you sure that $form->data['type'] exists?
If your code results in OR 'type' LIKE '%%' it will return every record.

Rob
flyboeing 17 Oct, 2013
The form->data['type'] refers to the 'type' input field. That input field has a name called 'type'. Maybe I am doing something wrong.

I thought that if I use 'OR' that it will look for reg OR type, not both. Is there a way to fix this? So When I fill in just one field in my form that it will show those results.
flyboeing 17 Oct, 2013
I also found out that my WHERE-query has to be changed:
'reg' LIKE '%<?php echo $form->data['reg']; ?>%' OR 'type' LIKE '%<?php echo $form->data['type']; ?>%' OR 'status' LIKE  '%<?php echo $form->data['status']; ?>%'

I removed the '' before the like (so not 'reg', but reg).

When I remove the rest of the query, so I only have reg LIKE '%<?php echo $form->data['reg']; ?>%', my search works.

But how does it work if you have more search criteria?
RobP 17 Oct, 2013

The form->data['type'] refers to the 'type' input field. That input field has a name called 'type'. Maybe I am doing something wrong.

I thought that if I use 'OR' that it will look for reg OR type, not both. Is there a way to fix this? So When I fill in just one field in my form that it will show those results.



The value of the input field gets in the Form data array when the form is submitted before that $form->data['type'] will be empty.
Also the query is run when the table data is loaded.

For dynamic filters you will need javascript, not PHP.

The OR checks both conditions, if one or both are true OR is true.
If you want to check if ony one is true the syntax is AND NOT or XOR

Rob
This topic is locked and no more replies can be posted.