Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » Add a contact form to the footer

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

Page: 1
Go to End
Author Topic: 1344 Views
  • wuzzi2ya
    Community Member
    7 Posts

    Add a contact form to the footer Link to this post

    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">

       <% if Success %>
       <% else %>
       <% end_if %>

    ContactPage.php: in mysite/code/

    /* *****************
    * 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
          //populate template
          //send mail
           //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?


  • _Vince
    Community Member
    161 Posts

    Re: Add a contact form to the footer Link to this post

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


    before the changes become visible. Did you try that?

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.