SilverStripe 5 - Custom Page Type Search Form - Results Not Appearing Below Form

I need help with a search form that won’t show results

I’m working on a custom search feature for events in SilverStripe 5. The search form displays correctly in my EventSearchPage.ss template, and the form submission works fine. The controller method processEventSearch() can filter the events based on user input, but the filtered results don’t appear below the form.

Here’s my controller code:

<?php

use SilverStripe\Forms\Form;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\ORM\PaginatedList;
use SilverStripe\Control\Controller;

class EventSearchPageController extends PageController
{
    private static $allowed_actions = [
        'EventFilterForm',
        'processEventSearch',
    ];

    public function EventFilterForm(): Form
    {        
        $categories = [
            'Conference' => 'Conference',
            'Workshop' => 'Workshop', 
            'Seminar' => 'Seminar',
            'Meeting' => 'Meeting',
            'All' => 'All'
        ];

        $venues = [
            'Indoor' => 'Indoor',
            'Outdoor' => 'Outdoor',
            'Virtual' => 'Virtual',
            'Mixed' => 'Mixed',
            'All' => 'All'
        ];

        $fields = FieldList::create(
            TextField::create('EventTitle')
                ->setAttribute('placeholder', 'Search event name')
                ->addExtraClass('form-control'),
            TextField::create('EventDate', 'Event date')
                ->setAttribute('placeholder', 'DD-MM-YYYY')
                ->addExtraClass('form-control'),
            DropdownField::create('Category', 'Event category')
                ->setSource($categories)
                ->addExtraClass('form-control'),
            DropdownField::create('Venue', 'Venue type')
                ->setSource($venues)
                ->addExtraClass('form-control')
        );

        $actions = FieldList::create(FormAction::create('processEventSearch'));
        $form = Form::create($this, 'EventFilterForm', $fields, $actions);
        
        return $form;
    }

    public function processEventSearch(HTTPRequest $request)
    {
        $data = $request->postVars();
        
        $eventTitle = $data['EventTitle'];
        $eventDate = $data['EventDate'];
        $category = $data['Category'];
        $venue = $data['Venue'];
        
        $events = EventPage::get()->filter(['Published' => true])->sort('EventDate DESC');
        
        if (!empty($eventTitle)) {
            $events = $events->filter(['EventTitle:PartialMatch' => $eventTitle]);
        }
        
        if (!empty($category) && $category != 'All') {
            $events = $events->filter('Category', $category);
        }
        
        if (!empty($venue) && $venue != 'All') {
            $events = $events->filter('Venue', $venue);
        }
        
        $paginatedEvents = PaginatedList::create($events, $request)
            ->setPageLength(12);
        
        return [
            'SearchResults' => $paginatedEvents,
        ];
    }
}

My template EventSearchPage.ss:

<div class="search-container">
    <h2>Find Events</h2>
    $EventFilterForm
    <% include EventSearchResults %>
</div>

And the results template EventSearchResults.ss:

<div class="results-section">
    <% if $SearchResults %>
        <div class="event-grid">
            <% loop $SearchResults %>
                <div class="event-item">
                    <h4><a href="$Link">$EventTitle</a></h4>
                    <p>Date: $EventDate.Format('dd/MM/yyyy')</p>
                    <p>Category: $Category</p>
                    <p>Venue: $Venue</p>
                </div>
            <% end_loop %>
        </div>
    <% else %>
        <p>No events found matching your criteria.</p>
    <% end_if %>
</div>

The search form works but no results show up in the template. What am I missing here?

hmm, it seems like your processEventSearch might not be linking the results correctly to the view. Are you using the right template variable for SearchResults? Maybe try echoing some values to see if they’re there? Just curious!

you’re missing a redirect back to the page after processing the form. add return $this->redirectBack(); at the end of your processEventSearch method, or return the rendered template with the data instead of just the array.

Your processEventSearch method returns an array but doesn’t render it back to the template. In SilverStripe, form submissions need to return the page with data context. Change your method to return $this->customise(['SearchResults' => $paginatedEvents])->renderWith('EventSearchPage'); instead of just the array. This passes the search results to your template and renders them on the same page. I had the exact same problem with a product search feature - this fixed it.