10447 Posts in 2223 Topics by 1719 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1093 Views |
-
Displaying form on other Page from Generic View CollectionPage

3 June 2010 at 1:18am
Hello,
I have my Generic View's module CollectionPage, where a $SearchForm and all results from my DataObject(called Job) are displayed.
Everything is fine, but what I need is to add the same $SearchForm to my HomePage, that would lead it's action to my CollectionPage once results are entered and submit button is pressed. The form is automatically generated by Generic View modules, so I can't replicate it, because it is generated based on $searchable_fields and also adds data to DropdownFields.
Any ideas on how could I grab that form and use it on my HomePage?
Thanks in advance.
-
Re: Displaying form on other Page from Generic View CollectionPage

6 June 2010 at 8:46am
HI
First you define a getCustomSearchContext method inside your DataObject Class like this
function getCustomSearchContext() {
$fields = $this->scaffoldSearchFields(array (
'restrictFields' => array (
'Description' => 'Description',
'Approval_Status'=>'Approval_Status'
)
));
$filters = array (
'Description' => new PartialMatchFilter('Description'),
'Approval_Status' => new ExactMatchFilter('Approval_Status')
);
return new SearchContext($this->class, $fields, $filters);
Create you form in mysite code
<?php
class YourSearchForm extends Form {function __construct($controller, $name) {
$context = singleton('YourDataObject')->getCustomSearchContext();
$fields = $context->getSearchFields();
$actions = new FieldSet(new FormAction('doSearch', 'Search'));
//$form = new Form($this, "SearchForm",$fields, $actions);
parent :: __construct($controller, $name, $fields, $actions);
}
public function doSearch($data, $form) {
$context = singleton('Classified')->getCustomSearchContext();
$results = $context->getResults($data);
return $this->customise(array(
'Results' => $results
))->renderWith(array('Classified_results', 'Page'));
}
function getResults($searchCriteria = array()) {
$start = ($this->request->getVar('start')) ? (int)$this->request->getVar('start') : 0;
$limit = 20;
$context = singleton('Classified')->getCustomSearchContext();
$query = $context->getQuery($searchCriteria, null, array('start'=>$start,'limit'=>$limit));
$records = $context->getResults($searchCriteria, null, array('start'=>$start,'limit'=>$limit));
if($records) {
$records->setPageLimits($start, $limit, $query->unlimitedRowCount());
}
return $records;
}
}
?>then Initiate your Form either at Page_Controller or HomePage_Controler like this
function YourSearchForm () {
return new YourSearchForm ($this, 'YourSearchForm ');
}HomePage.ss
$YourSearchForm
-
Re: Displaying form on other Page from Generic View CollectionPage

7 June 2010 at 11:30pm
This would really work out for me, and the form gets displayed if not one thing - returned results page.
On my domain/job-seekers is assign CollectionController page with a search form and lisf of results and when searching the results get updated straight away. That's what I would like to get: once the search query is entered on the homepage form, it is redirected to "job-seekers" page with a search executed to that data. Basically, I just need somehow to grab that form that would lead to job-seekers results.
-
Re: Displaying form on other Page from Generic View CollectionPage

9 June 2010 at 10:52pm
I've tried this way:
<% control Page(job-search) %>
$SearchForm
<% end_control %>Weird thing is that if I change $SearchForm into $Title, it displays title of /job-search/ page properly, but it doesn't show the $SearchForm on my HomePage. Any ideas?
| 1093 Views | ||
|
Page:
1
|
Go to Top |


