Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to create an address book in SS?


Go to End


18 Posts   4853 Views

Avatar
bummzack

Community Member, 904 Posts

23 January 2010 at 11:56pm

Edited: 24/01/2010 12:01am

Avatar
haantje72

Community Member, 69 Posts

24 January 2010 at 12:52am

Edited: 24/01/2010 2:05am

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

Avatar
haantje72

Community Member, 69 Posts

24 January 2010 at 1:19am

Edited: 24/01/2010 1:22am

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 :)

Avatar
haantje72

Community Member, 69 Posts

14 February 2010 at 10:52pm

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

Avatar
haantje72

Community Member, 69 Posts

6 March 2010 at 7:06am

Anyone? I have no clue how to! But if its possible i want to have an minimum input.
Thanks for reply

Avatar
innyinskip

Community Member, 46 Posts

2 July 2010 at 2:16am

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

Avatar
Willr

Forum Moderator, 5523 Posts

2 July 2010 at 4:45pm

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.

Avatar
innyinskip

Community Member, 46 Posts

22 July 2010 at 7:33pm

Quick Question, Could this be done by using an external php address book andthen including that into the SS template files?