15 Posts
4 years ago


I am struggeling with "beforesearch" (code pack) on al list & search type to set a value before search. But I did not found any hint or help on seblod.com. I tried to add code on the "hidden" part on the search form, but now result so far.

What I want to achieve:

I want to filter a list of articles with two dates. The articles are about "events" of our club. Some events have an start and end date, some only a start date. Events with a start date in the past should be filtered out, expect if the there is an end date which lies in the future. Therefore I want to use the value of the end date for the search filter instead of the start date. End date is 0000-00-00 00:00:00 eg. empty when not used.


I tried to add a beforesearch field with the following code:

$start = $fields['event_date_start']->value;
$end = $fields['event_date_end']->value;

if ($end == 0) {
$fields['event_date_filter']->value = $start;
} elseif ($end !== 0) {
$fields['event_date_filter']->value = $end;


I added in the "main" part of the search form a "JForm calendar" field "event_date_filter" an set 3 to "Future (> or =)" and the live value to "1 day -1 day".

I know how to use "beforerender" and I had no problem so far with the code pack. But beforesearch is a riddle for me...


kind regards


Get a VIP membership
4 years ago
Level 1

Hi Michael,

On the "beforeSearch" event, the $fields array is "a bit" different than in other events. You'll be able to get/set fields using:

  • $fields['search']['your_field_name']
  • $fields['order']['your_field_name']


15 Posts
4 years ago
Level 2

Hello Saba

Thanks a lot for your quick answer.


I tried the following, but no result so far.


I put the code below in a beforsesearch field in the "Hidden" position in the "Search Form" view. Also the two fields with the start date and end date from the articles. I created a new JFrom Calendar field with none storage in the "Main" position called "event_date_search".


$start = $fields['search']['event_date_start']->value;
$end = $fields['search']['event_date_end']->value;

if ($end == 0) {
$fields['search']['event_date_search']->value = $start;
} elseif ($end !== 0) {
$fields['search']['event_date_search']->value = $end;


For me, it is not clear where to put the fields, the beforesearch and the one I want to change (in my case "event_date_search")? Is it in the view "Search Form"? Or in the "List"? Do I have to replace the ['search'] option with something else?


A short step by step explanation would be helpful. I am sure "beforesearch" is extremely useful.


Best regards


Get a Book for SEBLOD