Jump to:

2002 Posts in 1422 Topics by 616 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: 1319 Views
  • wuzzi2ya
    Avatar
    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">

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

  • _Vince
    Avatar
    Community Member
    158 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

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

    before the changes become visible. Did you try that?

    1319 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.