I'm trying ti implement a search form, and a bit confused on how to build the results page.

I built my /etc/routes.xml file (updated id and frontName)

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="fitment_results" frontName="fitment_results">
            <module name="EkkoMedia_FitmentSearch"/>

And my /Controller/Index.php file


namespace EkkoMedia\FitmentSearch\Controller;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\View\Element\Messages;
use Magento\Framework\View\Result\PageFactory;

class Result extends Action
    /** @var PageFactory $resultPageFactory */
    protected $resultPageFactory;

     * Result constructor.
     * @param Context $context
     * @param PageFactory $pageFactory
    public function __construct(Context $context, PageFactory $pageFactory)
        $this->resultPageFactory = $pageFactory;

     * The controller action
     * @return \Magento\Framework\View\Result\Page
    public function execute()
        $year = $this->getRequest()->getParam('year');

        $resultPage = $this->resultPageFactory->create();

        /** @var Messages $messageBlock */
        $messageBlock = $resultPage->getLayout()->createBlock(
        if (isset($year)) {
            $messageBlock->addSuccess('Year: ' . $year);
            $messageBlock->addError('You didn\'t enter a year!');


        return $resultPage;

And my /view/frontend/layout/fitment_results_index.xml file (updated file name)

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">

But when I submit my form (action="fitment_results"), I get a 404 error

UPDATE (Added phtml)

<div class="container">
    <form id="productSearch" action="fitment_results" method="get">
        <select name="year" id="select_year" class="ui-selectmenu-button" tabindex="1">
            <option value="2004">2004</option>

        <select name="make" id="select_make" tabindex="2">
            <option value="">Make</option>
            <option value="Ford">Ford</option>

        <select name="model" id="select_model" tabindex="3">
            <option value="">Model</option>
            <option value="F-150">F150</option>

        <select name="trim" id="select_trim" tabindex="4">
            <option value="">Model</option>
            <option value="FX4">FX4</option>

        <input type="submit" id="search_submit" value="Find Products">

enter image description here

As you can see, the routeId can not contain the '-' character. You should change the routeId and routeName to fitment_results. Hope it help!

  • Made the change to both my routes.xml and my form action, but still getting a 404 – cvassios Dec 15 '17 at 1:11
  • For clarification, is the routeName the URL? – cvassios Dec 15 '17 at 1:12
  • routeName is your base url of your module – Nero Phung Dec 15 '17 at 1:12
  • Try to remove var/generation folder and clean cache – Nero Phung Dec 15 '17 at 1:13
  • In that case, what if my module is a block being displayed in the header of every page, rather than its own page? – cvassios Dec 15 '17 at 1:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.