Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » Create e-mail from in base page

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

Page: 1
Go to End
Author Topic: 470 Views
  • PeterR
    Community Member
    1 Post

    Create e-mail from in base page Link to this post


    I´m stucked with creating custom e-mail form. I tried to follow tutorials & topics but something gone wrong

    My target is to create an custom e-mail form which will be available in the footer on all site pages.

    So I modify mysite/code/Page.php
    class Page extends SiteTree {

       public static $db = array(

       public static $has_one = array(

    class Page_Controller extends ContentController {

       public function init() {

    static $allowed_actions = array('HelloForm');

    public function HelloForm()
    return new MyForm($this, 'HelloForm');

    class MyForm extends Form
       public function __contruct($controller, $name)
          $fields = new FieldList(
    $actions = new FieldList(
    FormAction::create('submit', 'Submit')->addExtraClass('button-send')
    parent::__contruct($controller, $name, $fields, $actions);
    public function submit($data, $form)
          // sending e-mail ....       
       public function forTemplate()
          return $this->renderWith(array($this->class, 'Form'));

    in footer.ss I have $HelloForm
    and here is my templates/simple/includes/MyForm.ss

    <form $FormAttributes>
    <% if $Message %>
    <p id="{$FormName}_error" class="message $MessageType">$Message</p>
    <% else %>
    <p id="{$FormName}_error" class="message $MessageType" style="display: none"></p>
    <% end_if %>

       <div class="contact-left">
       <div class="contact-right">         

    <% if $Actions %>
    <div class="Actions">
    <% loop $Actions %>$Field<% end_loop %>
    <% end_if %>

    the problem is that page is generated with error

    [User Error] Uncaught InvalidArgumentException: $fields must be a valid FieldList instance

    in \framework\forms\Form.php

    so the problem is with calling parent method. But I already sent $fields which is declared in MyForm contructor method, so... ?

    I do not know how to fix it...I am using Silverstripe 3.0.5.

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.