Jump to:

3212 Posts in 847 Topics by 809 members

Template Questions

SilverStripe Forums » Template Questions » [SOLVED] custom template issues SS.30

Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 192 Views
  • Harley
    Avatar
    Community Member
    144 Posts

    [SOLVED] custom template issues SS.30 Link to this post

    Hi there,

    I'm currently trying to add a form with a simple email field into the header include of my theme so I can populate the newsletter module from any page with a "Newsletter sign up" feature.

    I can get the form to display and function if I have it directly in my Page.php but now I'm trying to break it out and use it as a form extension like so:

    newslettersignup
    - code
    - NewsletterForm.php
    - templates
    - Includes
    - NewsletterForm.ss
    _config.php

    I'm not exactly sure why but it doesn't seem to render with it's own template, here is my code:

    NewsletterForm.php

    <?php

    class NewsletterForm extends Form{

    public function __construct($controller, $name) {

          public function NewsletterFormData(){
             $fields = new FieldList(
                new EmailField("Email", "Sign up to our news letter", "your email address")
             );

             if(Session::get('PageTypeWatcher') == 'SubscriptionPage'){
                $actions = new FieldList(
                   new FormAction("NewsletterForm", "»")
                );
             } else {
                $actions = new FieldList(
                   new FormAction("PassNewsletterForm", "»")
                );
             }

             $required = new RequiredFields("Email");

             parent::__construct($controller, $name, $fields, $actions, $required);
           }

           public function forTemplate() {
        return $this->renderWith(array($this->class, 'Form'));
        }

           public function PassNewsletterForm($data, $form) {
           
          if($data['Email']){
             Session::set('Email', $data['Email']);
             return $this->redirect(Director::baseURL() . 'newsletter');
             }
          }

           public function NewsletterForm($data, $form) {
           
          if($data['Email']){
             Session::set('Email', $data['Email']);
             return $this->redirect(Director::baseURL() . $this->URLSegment . '/?return');
             }
          }
       }
    }

    ?>

    NewsletterForm.ss

    <form $FormAttributes>
       <fieldset>
          <% loop Fields %>
             $FieldHolder
          <% end_loop %>
          <% loop Actions %>
             $Field
          <% end_loop %>
       </fieldset>
    </form>

    Any ideas?

    Many thanks

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