I have created a form in the page_controller, so that it can be included in any other page which may require it. the code are as follow:
/**
* Site search form
*/
function DirectorySearchForm() {
$theme_dir = $this->ThemeDir();
$default_category = (isset($_GET['Category']))?$_GET['Category']:'';
$default_business_name = (isset($_GET['BusinessName']))?$_GET['BusinessName']:'';
$mycat = array();
$this->build_category_tree($mycat);
$searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : '';
$fields = new FieldSet(
new LiteralField ("cate_span", '<span class="choose-category">Choose a business category</span>'),
new SearchFormDropDownField(
'Category',
'',
$mycat,
$default_category,
'',
'Any Category'
),
new LiteralField ("business_span", '<span class="business-name">Business name</span>'),
new TextField("BusinessName", "", $default_business_name)
);
$myFormAction = new FormAction('searchResultProcess', 'SEARCH');
$myFormAction->addExtraClass('submitBtn');
$actions = new FieldSet($myFormAction);
$mySearcgForm = new SearchForm($this, "DirectorySearchForm", $fields, $actions);
$mySearcgForm->addExtraClass('search_form');
return $mySearcgForm;
}
/**
* Process and render search results
*/
function searchResultProcess($data, $form){
$page = DataObject::get('SearchResultPage', "", 'Sort', '', 1);
$result_page = $page->First();
$link = $result_page->Link();
Director::redirect($link.'?BusinessName='.urlencode($data['BusinessName']).'&Category='.urlencode($data['Category']));
}
the process actually pass on the param to search result page, which will then be processed.
The problem that I am facing is that, this technique works in early versions. But with 2.4.5, after I turned on the 'enable_nested_urls'. This settings change the director behavior I guess. Now only level one directory will finds the DirectorySearchForm, any directory deeper than this will result in 404. take the following two page as example.
http://www.mydomain.com/business-directory/
this will work as expected.
http://www.mydomain.com/business-directory/professional-services/
form on this page does not work, will result in 404 page.
I have a feeling that it might have something to do with the 'Director' rules set up by the nested url. I have two level directory sitting under the 'business-directory'. Does anyone know how to solve this problem, not sure how to go about setting up the redirect rules for this. Please help. Cheers.