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

Custom Form Rendering


5 Posts   6737 Views


9 June 2009 at 2:28am Community Member, 2 Posts


What i like to know is: How is it possible to create custom forms?
I like to display a custom form, but it seems that the form attributes wouldn't be parsed...

So, here is my setup:
1. I have my custom Page (KMForm_Page) / PageController (KMFormPage_Controller)
The Controller looks like this:
class KMFormPage_Controller extends Page_Controller
function KMForm()
return new KMForm($this,'KMForm');



2. I do of course have a custom Form (KMForm) as used above:
class KMForm extends Form
function __construct($controller, $name)
$fields = new FieldSet(
new EmailField('email', 'E-Mail-Adresse'),
new TextField('telefon', 'Telefonnummer')

$actions = new FieldSet(
new FormAction('submit', 'Absenden')

$requiredFields = new RequiredFields('email');

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

function forTemplate()
// Erwartet Template mit Namen 'KMForm'
return $this->renderWith(array(

function submit($data, $form)

3. I have a appropriate Template
<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 id="email" class="field email">
<label for="$Form_email">E-Mail-Adresse</label>
<div id="telefonnummer" class="field telefon">
<label for="$FormName_telefon">Telefonnummer</label>

<% if Actions %>
<div class="Actions">
<% control Actions %>
<% end_control %>
<% end_if %>


Site displays, but:
- The Rendering of the Variables $FormAttributes, $FormName, $Form_email etc. doesn't happen at all
- site displays only the non-dynamic items of

So, as usual the failure sits in front of the PC...
Any hints, what i'm doing wrong?

Thanks for your time!


19 June 2009 at 8:48am Community Member, 13 Posts

I've gotten past the point you have described in this posting (but am stumped by not activating the submit routine, got any hints on that?).

Question: Do you have a $KMForm in the page layout template for KMFormPage_Controller?

I would also advise putting a <% debug %> in both 'ss' files to see what methods are available. Most likely the 'ss' file is being activated on the wrong class object.


24 June 2009 at 12:32pm (Last edited: 24 June 2009 12:34pm), Community Member, 80 Posts

Not 100% sure, however you may try following two points:
1. make sure is in 'templates/Includes' directory.
2. it seems that you form function and form class has the same name, what I did recently is given the form subclass a different name. ie MyForm extends Form, then in your page controller, do

function MyFirstForm(){
      return new MyForm($this, 'MyFirstForm');

In your case, maybe it is better to change sub class name, because you need match the function name.

Hope it will help


25 March 2011 at 9:24am Community Member, 41 Posts

I have similar issue, and I need help!!!

My code is pretty similar to what she posted
Also I smpled this page:

#1. is in templates/Includes directory
#2. In my page controller, I just put this

function MyFirstForm(){
return new MyForm($this, 'MyFirstForm');
} is display fine but "$dataFieldByName()" is NOT working.

I have this in my MyForm.php

$fields = new FieldSet(
new TextField('FirstName', 'First name'),
new EmailField('Email', 'Email address')

so I have


in my but they are not displaying anything.
It supposed to show

<input type='text' ..... >


What is wrong?


12 January 2012 at 1:27pm Community Member, 19 Posts

I was having similar issues. Check this forum post. It was my answer: