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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

submit is not working (template form)

Go to End

3 Posts   2087 Views


Community Member, 41 Posts

9 April 2011 at 12:05pm

When I click submit button, just refreshing page. (nothing happened. Validation is not working neither)

What do I need to fix?

I'm using template form (


class Landing_Controller extends Page_Controller {
	static $allowed_actions = array(

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


class MyForm extends Form {
function __construct($controller, $name) {
      $fields = new FieldSet(
         new TextField('name', 'name', 'first','20')
         new EmailField('Email', 'Email address'),

      $actions = new FieldSet(
         new FormAction('sendRequest', 'send request')
      $validator = new RequiredFields('name',  'Email'');

      parent::__construct($controller, $name, $fields, $actions, $validator);
   function forTemplate() {
      return $this->renderWith(array(

   public function sendRequest($data, $form) {
       //submit code

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




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


Community Member, 96 Posts

7 May 2011 at 7:19pm

If you want to refresh the page, I think you must add something like this in your MyForm.php:

public function sendRequest($data, $form) {
header( 'location:' )

In any case the sendRequest-function is called, if you press the submit-button.


Community Member, 80 Posts

9 May 2011 at 6:16pm

For your validation to work, put the fields into array as follow:

$validator = new RequiredFields(array('name', 'Email'));

you will also need a submission class to construct your database table.

class ContactUsSubmission extends DataObject {
static $db = array(
'name' => 'Varchar(255)',
'Email' => 'Varchar(255)'

You then use this class in your process function so that your script knows where to store the data captured by your form. in your case the function is sendRequest()

public function sendRequest($data, $form){
$submission = new ContactUsSubmission();

//then you need to redirect user to thank you page or any page you want.

Here is a nice tutorial on a basic contact us form, however be aware it does not extend the Form class as you did. I recommend you to start with this easy tutorial.