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 /

Problem with Tutorial 3

Go to End



Community Member, 1 Post

14 August 2013 at 2:22am

Edited: 14/08/2013 2:32am

Hi all

I am evaluating SS 3.0.5 and the tutorials. Now i have a Problem with tutorial 3 ( Neither validation exception nor the redirectBack is working. Submitting with missing fields just Returns to the page without any message. And when submitting both fields, the result is not shown.

Here is my code from mysite/code/HomePage.php

class HomePage extends Page {


class HomePage_Controller extends Page_Controller {
   public function LatestNews($num=1) {
      $holder = ArticleHolder::get()->First();
      return ($holder) ? ArticlePage::get()->filter('ParentID', $holder->ID)->sort('Date DESC')->limit($num) : false;
   static $allowed_actions = array('BrowserPollForm');

   public function BrowserPollForm() {
      if(Session::get('BrowserPollVoted') == true)
         return false;

      // Create fields
      $fields = new FieldList(
         new TextField('Name'),
         new OptionsetField('Browser', 'Your Favourite Browser', array(
                            'Firefox' => 'Firefox',
                            'Chrome' => 'Chrome',
                            'Internet Explorer' => 'Internet Explorer',
                            'Safari' => 'Safari',
                            'Opera' => 'Opera',
                            'Lynx' => 'Lynx'
      // Create actions
      $actions = new FieldList(
         new FormAction('doBrowserPoll', 'Submit')

      $validator = new RequiredFields('Name', 'Browser');
      return new Form($this, 'BrowserPollForm', $fields, $actions, $validator);
   public function doBrowserPoll($data, $form) {
      $submission = new BrowserPollSubmission();

      Session::set('BrowserPollVoted', true);

      return $this->redirectBack();

   public function BrowserPollResults() {
      $submissions = new GroupedList(BrowserPollSubmission::get());
      $total = $submissions->Count();

      $list = new ArrayList();
      foreach($submissions->groupBy('Browser') as $browserName => $browserSubmissions) {
         $percentage = (int) ($browserSubmissions->Count() / $total * 100);
         $list->push(new ArrayData(array(
                           'Browser' => $browserName,
                           'Percentage' => $percentage
      return $list;

I hope somebody may help me.

using return $this->redirect(""); would make the submit work. but what's the difference?