Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » EventCalendar - Opening extra page from Announcements

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 903 Views
  • silk
    Avatar
    Community Member
    18 Posts

    EventCalendar - Opening extra page from Announcements Link to this post

    Hi,

    after creating my own announcements (see here, thank's UncleCheese) I want to proceed from there.

    In my calendar the events are shown in a list just as usual. Now I want to have for each announcement a link to a contact form. All contact data is available from the DateTime entry.

    This leads to a more general Silverstripe question:
    How can I create (and link to) a page which does not exist in the site tree. Normally, all pages are present in the side tree. I don't want to do that, now.
    I could alter my calendar template so that the contact form is shown in the list of events (like the title, date and description), I guess. Instead I want to open a new page for that. How can this be achieved?

    I found some hints to do it with ajax (1, 2), but still didn't get it to work. First step should be a normal page before doing it with ajax, shouldn't it? Likely the renderWith function plays a crucial part, but where and when?

    Does anybody know some reference or tutorial how to do it? I couldn't find anything other than the links above.

    Christian

  • UncleCheese
    Avatar
    4085 Posts

    Re: EventCalendar - Opening extra page from Announcements Link to this post

    I'm not sure I understand... you need each announcement to link to a unique contact form? For what purpose? Give some context and I can help you out.

  • silk
    Avatar
    Community Member
    18 Posts

    Re: EventCalendar - Opening extra page from Announcements Link to this post

    Ok, thank's. I'll try to explain it more clearly:

    Each announcement now has a field for a contact email. Customers should be able to send messages to this email address to register or ask questions. Therefore, I want to have a contact form.
    I don't want to have the contact form to be there for all announcements, all the time. Instead I only want to have some link/icon that is used to open the contact form (on a new page).

    The template for the form will be the same for all announcements, but the used email and subject information depends on the announcement associated with the form.

  • UncleCheese
    Avatar
    4085 Posts

    Re: EventCalendar - Opening extra page from Announcements Link to this post

    Yeah, so you want to create a link to the contact page for each announcement first...

    So on your DateTime subclass

    public function ContactFormLink()
    {
    $page = DataObject::get_one("YourContactPage");
    return $page ? Controller::join_links($page->URLSegment, 'contact', $this->ID) : false;
    }

    Then on your contact form page, create a function called "contact" that gets the DateTime object by ID, and returns the form with all the values set according to that object.

  • silk
    Avatar
    Community Member
    18 Posts

    Re: EventCalendar - Opening extra page from Announcements Link to this post

    First, thanks a lot for your advise!
    Unfortunately, it does not work and I do not really understand how it should work.

    First: I need to have some dummy YourContactPage in the site tree to make $page = DataObject::get_one("YourContactPage") work, right? I can live with that, but I want to understand what is done here.

    Second, I'm not understanding why/how
    Controller::join_links($page->URLSegment, 'contact', $this->ID)
    works.

    The join_links Documentation sounds too simple.
    Finally, I don't understand what to do in contact.

    I have done:
    I created a class YourContactPage:

    class YourContactFormPage extends Page {

    static $emailToUser;

    public function contact($id){
        $dateTime = DataObject::get_by_id("YourDateTime", $id);   
        self::$emailToUser=$dateTime->OrganizerMemberID;   
    return self; //not sure what to return
    }
    };

    There is also a controller:

    class YourContactFormPage_Controller extends Page_Controller {

    function EmailForm() {
    // Create fields
    $fields = new FieldSet(
    new TextField('name','Absender Name'),
    new EmailField('emailFrom', 'Absender E-Mail'),
    new TextField('subject', 'Betreff'),
    new TextAreaField('body', 'Nachricht', 15, 50, '')
    );
    // Create actions
    $actions = new FieldSet(
    new FormAction('doSendEMail', 'Absenden')
    );
    return new Form($this, 'EmailForm', $fields, $actions);
    }

    function doSendEmail($data, $form){
    $member = DataObject::get_by_id("Member", $this->emailToUser);   
    $emailTo = $member->Email;
    print $emailTo;

    $email = new Email($data['emailFrom'], $emailTo, $data['subject'], $data['body']);
    $email->send();          
    Director::redirectBack();
    }
    };

    You wrote:
    "Then on your contact form page, create a function called "contact" that gets the DateTime object by ID, and returns the form with all the values set according to that object."

    Finally, I don't understand what to return. The page or should I do something like in EmailForm()?

  • silk
    Avatar
    Community Member
    18 Posts

    Re: EventCalendar - Opening extra page from Announcements Link to this post

    Is there anybody who knows the answers?
    I'm really stuck, right now.

  • UncleCheese
    Avatar
    4085 Posts

    Re: EventCalendar - Opening extra page from Announcements Link to this post

    Well it's not exactly a one-liner. You're going to have to intuit a lot of this stuff because it's really more code than I can post in a forum.. but here's the idea.

    YourDateTimeSubclass.php

    public function ContactLink()
    {
    if($page = DataObject::get_one("YourContactPage")) {
    return Controller::join_links($page->URLSegment, 'contact', $this->ID);
    }
    return false;
    }

    That will generate a link on each announcement to /your-contact-page-url/contact/123, where 123 is the ID of your annoucement.

    Then you need to handle the incoming request for the contact form.

    YourContactPage.php

    class YourContactPage extends Page
    {
    // db fields.. maybe for to/from fields... success message text
    }

    class YourContactPage_Controller extends Page_Controller
    {
    public function ContactForm()
    {
    $id = $this->urlParams['ID'] ? $this->urlParams['ID'] : (isset($_REQUEST['AnnouncementID']) ? $_REQUEST['AnnouncementID'] : false);

    // Sanity check
    if(!$id) return Director::redirectBack();

    return new Form (
    $this,
    "ContactForm",
    new FieldSet(
    new HiddenField('AnnouncementID','',$id),
    // more fields here
    ),
    new FieldSet( new FormAction('doSubmit','Send'))
    );
    }

    public function doSubmit($data, $form)
    {
    if(isset($data['AnnouncementID']) && is_numeric($data['AnnouncementID'])) {
    if($announcement = DataObject::get_by_id("YourDateTimeClass", $data['AnnouncementID'])) {
    // create an email...
    $subject = "Question about $announcement->Title"; // for instance..

    }
    }
    }
    }

    Does that make a little more sense?

  • UncleCheese
    Avatar
    4085 Posts

    Re: EventCalendar - Opening extra page from Announcements Link to this post

    YourContactPage_contact.ss

    $ContactForm

    903 Views
Page: 1
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.