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:

Widgets /

Discuss SilverStripe Widgets.

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

Contact form widget - Posting problems

Go to End

3 Posts   4123 Views


Community Member, 35 Posts

25 July 2009 at 5:32am

I have made a contact form based on this document:

I have this code in the file ContactWidget:


class ContactWidget extends Widget {
static $db = array(
"Text" => "Varchar"

static $title = "Kontakt oss";
static $cmsTitle = "Contact";
static $description = "Contact form in sidebar.";

function Form() {
$controller = new ContactWidget_Controller($this);
return $controller->Form();

function getCMSFields() {
return new FieldSet(
new TextField("Text", "Tekst")

class ContactWidget_Controller extends Controller {
protected $widget;

function __construct($widget = null) {
if($widget) $this->widget = $widget;
function widget() {
if($this->widget) return $this->widget;
else if(is_numeric($this->urlParams['ID'])) return $this->widget = DataObject::get_by_id('Widget', $this->urlParams['ID']);
else user_error('No widget selected', E_USER_ERROR);
function Link() {
return $this->class;

function Form() {
// ... This can be whatever form you like ...
$widgetform = new WidgetForm($this, 'Form', new FieldSet(
new DropdownField('Browser', 'Hva er du interissert i?', array(
'Annonsestyring' => 'Annonsestyring',
'Publiseringsløsning' => 'Publiseringsløsning')),
new TextField('Name', 'Navn'),
new TextField('Email', 'E-post')),
new FieldSet(new FormAction('doAction', 'Submit')));

return $widgetform;

function doAction($data, $form) {
// ... Do your thing, just like a normal SilverStripe form

// ... This is a good way of giving feedback to the user about the submission. A message will be shown above the form.

$this->Form()->sessionMessage("Thanks for submitting my form", "good");

class WidgetForm extends Form {
protected $widget;

static $url_handlers = array(
'POST $WidgetID' => 'httpSubmission',
'GET $WidgetID' => 'httpSubmission'

function FormAction(){
return parent::FormAction()."/".$this->widget->ID;
return parent::FormAction();

function setWidget($wgt){
if($wgt != null){
$this->widget = $wgt;

function getWidget(){
return $this->widget;


The form is displayed as it should in the sidebar, but when I submit the form I get this error message:

Website Error
There has been an error

The website server has not been able to respond to your request.

I suppose the form should be posted on the same page that it's displayed, but it is posting to I just can't see what I have done wrong. Hope some some of you experts out there can see it!? Then I will be really grateful!


Community Member, 63 Posts

3 February 2010 at 9:23am

Did u solve ur issue ? because I have the same issue !


Community Member, 52 Posts

14 February 2010 at 3:36am

I also have the same problem, by editing the function FormAction in WidgetForm.php you might modify where the action is redirected.
However, I can't get the doAction function to work, it seems that it never get's there...
Can someone help ?