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.

Form Questions /

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

Add a contact form to the footer


Go to End


2 Posts   2260 Views

Avatar
wuzzi2ya

Community Member, 7 Posts

21 May 2010 at 3:59pm

How if possible do I go about adding my content form to the footer, preferably as an include as i would like it on all pages. I used:

ContactPage.ss: in templates/layout/

<div id="LeftColumn"></div>
<div class="typography">

<h2>$Title</h2>

<% if Success %>
$SubmitText
<% else %>
$Content
$ContactForm
<% end_if %>

</div>

ContactPage.php: in mysite/code/

<?php
/* *****************
* Model
******************/
class ContactPage extends Page
{
static $db = array(
'Mailto' => 'Varchar(100)', //Email address to send submissions to
'SubmitText' => 'HTMLText' //Text presented after submitting message
);

//CMS fields
function getCMSFields() {
$fields = parent::getCMSFields();

$fields->addFieldToTab("Root.Content.OnSubmission", new TextField('Mailto', 'Email submissions to'));
$fields->addFieldToTab("Root.Content.OnSubmission", new HTMLEditorField('SubmitText', 'Text on Submission'));

return $fields;
}

}
/* *****************
* Controller
******************/
class ContactPage_Controller extends Page_Controller
{
function ContactForm() {
// Create fields
$Params = Director::urlParams();

$fields = new FieldSet(
new TextField('Name', 'Name*'),
new EmailField('Email', 'Email*'),
new TextareaField('Comments','Comments*')
);

// Create action
$actions = new FieldSet(
new FormAction('SendContactForm', 'Send')
);
// Create action
$validator = new RequiredFields('Name', 'Email', 'Comments');

return new Form($this, 'ContactForm', $fields, $actions, $validator);
}

function SendContactForm($data) {

//Set data
$From = $data['Email'];
$To = $this->Mailto;
$Subject = "Website Contact message";
$email = new Email($From, $To, $Subject);
//set template
$email->setTemplate('ContactEmail');
//populate template
$email->populateTemplate($data);
//send mail
$email->send();
//return to submitted message
Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");

}

public function Success()
{
return isset($_REQUEST['success']) && $_REQUEST['success'] == "1";
}
}
?>

...and my footer.ss is just an include:

I have successfully created a contact page that is visible when on the actual page from main nav, but I would like to have just the form appear within the footer. What do I need to do next? Do I need a holder page?

Thanks!

Avatar
_Vince

Community Member, 165 Posts

23 May 2010 at 10:59am

If the Footer is an include, I think you need to flush the cache

http://www.example.com?flush=1

before the changes become visible. Did you try that?