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.

Form Questions /

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

Create e-mail from in base page

Go to End



Community Member, 15 Posts

29 July 2013 at 6:51am


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 I have $HelloForm
and here is my templates/simple/includes/

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