Jump to:

22976 Posts in 11620 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » How to create an address book in SS?

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

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

Page: 1 2 3
Go to End
Author Topic: 2520 Views
  • banal
    Avatar
    Community Member
    901 Posts
  • haantje72
    Avatar
    Community Member
    69 Posts

    Re: How to create an address book in SS? Link to this post

    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

  • haantje72
    Avatar
    Community Member
    69 Posts

    Re: How to create an address book in SS? Link to this post

    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

  • haantje72
    Avatar
    Community Member
    69 Posts

    Re: How to create an address book in SS? Link to this post

    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

  • haantje72
    Avatar
    Community Member
    69 Posts

    Re: How to create an address book in SS? Link to this post

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

  • innyinskip
    Avatar
    Community Member
    46 Posts

    Re: How to create an address book in SS? Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: How to create an address book in SS? Link to this post

    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.

  • innyinskip
    Avatar
    Community Member
    46 Posts

    Re: How to create an address book in SS? Link to this post

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

    2520 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.