Maybe this post helps:
http://www.silverstripe.org/customising-the-cms/show/265671
Update These might be even better:
http://www.silverstripe.org/all-other-modules/show/259512
http://doc.silverstripe.org/doku.php?id=searchcontext
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Maybe this post helps:
http://www.silverstripe.org/customising-the-cms/show/265671
Update These might be even better:
http://www.silverstripe.org/all-other-modules/show/259512
http://doc.silverstripe.org/doku.php?id=searchcontext
The first link seems to work... copied the searchform into mysite/page.php
The only thing is that i deactivated the normal searchform (wich is for me no problem)
function SearchForm() {
$context = singleton('Contact')->getDefaultSearchContext();
$fields = $context->getSearchFields();
$actions = new FieldSet(new FormAction('doSearch', 'ok'));
$form = new SearchForm($this, "SearchForm", $fields, $actions);
return $form;
}
public function doSearch($data, $form) {
$context = singleton('Contact')->getDefaultSearchContext();
$results = $context->getResults($data);
return $this->customise(array(
'Results' => $results
))->renderWith( array ('Page_results', 'Page'));
}
Then changed the templates/....pageresults.ss to show not the link but $name, $address, $phone
<% control Results %>
<li>
<% if MenuTitle %>
<h3><a class="searchResultHeader" href="$Link">$MenuTitle</a></h3>
<% else %>
<h3><div class="searchResultHeader" href="$Link">$Title</div></h3>
<% end_if %>
<% if Content %>
$Content.FirstParagraph(html)
<% end_if %>
<p class="readMoreLink"">$Name, $Address, $Phone</p>
</li>
<% end_control %>
In the ContactPage.ss i just added the searchform
The only little problem is the text Name is behind the searchbox and Phone behind the ok button... instead of before the boxes...
still looking how to change this
Okay, the text i see i have to make margins in the css... so the text is above the form... but it seems to work only with one text and the second one displays still behind te first box in stead of above the second one so i had to change the width.
now it looks good and works great.
Thanks a lot Banal :)
mmmm... has anyone a suggestion how to get a minimum input in the searchform. Now when i leave the form blank and click on search all the adresses come up. Is there a way i can have a minimum input of 2 or 3 char.
thanks for reply
Anyone? I have no clue how to! But if its possible i want to have an minimum input.
Thanks for reply
Im stuck on the first part lol!
Im almost trynig to do the same as you.
I have created the CMS part but when trying to add custom fields. IE: Extention No. and DDI i get errors when trying to build the DB.
Once that is done i then want that to be a page on the frontend whereby a user could search for John and get all the Johns.
Contact.php
----------------------------------------------------------
<?php
class Contact extends DataObject
{
static $db = array (
'Name' => 'Varchar',
'Company' => 'Varchar',
'Extention' => 'Int',
'DDI' => 'Int',
);
static $searchable_fields = array(
'Name',
'Company'
'Extention'
'DDI'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new TextareaField('Company', "Company"),
new PhoneNumberField('Extention', "Extention"),
new PhoneNumberField('DDI', "DDI"),
);
}
}
?>
-------------------------------
ContactAdmin.php
--------------------------------------
<?php
class ContactAdmin extends ModelAdmin {
public static $managed_models = array(
'Contact'
);
static $url_segment = 'contacts'; // will be linked as /admin/contacts
static $menu_title = 'Address Book';
}
?>
Can someone please point me in the right direction?
Cheers
Craig
You're missing commas in
static $searchable_fields = array(
'Name',
'Company'
'Extention'
'DDI'
);
Should be
static $searchable_fields = array(
'Name',
'Company',
'Extention',
'DDI'
);
Make sure when you're developing you have display_errors in your php.ini turned on and that your site is in devmode. Will make your life easier.
Quick Question, Could this be done by using an external php address book andthen including that into the SS template files?