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.

All other Modules

Discuss all other Modules here.

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

EventCalendar - Opening extra page from Announcements


Reply

8 Posts   949 Views

Avatar
silk

23 March 2010 at 4:46am (Last edited: 23 March 2010 9:25pm), Community Member, 18 Posts

Hi,

after creating my own announcements (see [url=http://www.silverstripe.org/all-other-modules/show/277521#post277521]here[/url], 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 ([url=http://www.ssbits.com/using-a-thickbox-modal-window-with-ajax]1[/url], [url=http://doc.silverstripe.org/doku.php?id=recipes:ajax_basics]2[/url]), 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

Avatar
UncleCheese

23 March 2010 at 10:34am 4085 Posts

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.

Avatar
silk

23 March 2010 at 9:24pm Community Member, 18 Posts

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.

Avatar
UncleCheese

24 March 2010 at 1:55am 4085 Posts

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.

Avatar
silk

24 March 2010 at 9:06pm (Last edited: 31 March 2010 2:01am), Community Member, 18 Posts

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 [url=http://api.silverstripe.org/sapphire/control/Controller.html#join_links]join_links Documentation[/url] 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()?

Avatar
silk

31 March 2010 at 2:02am Community Member, 18 Posts

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

Avatar
UncleCheese

31 March 2010 at 3:59am 4085 Posts

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?

Avatar
UncleCheese

31 March 2010 at 4:00am 4085 Posts

YourContactPage_contact.ss

$ContactForm