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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Form builder link up with static form

Go to End

4 Posts   915 Views


Community Member, 151 Posts

15 July 2011 at 3:49am

Hi everyone

I have made a good start to the following website

There is a form on the right hand side, which is static in the template include. However I obviously want this to be Form2Mail and create a backup copy of the data entered in the backoffice system.

I dont really know where to start with this, does anyone have some ideas?

Thanks very much in advance for any help.


Community Member, 545 Posts

15 July 2011 at 4:15am

Take a look at

You could create a data object to store a backup copy of the form in the Database while mailing it to its intended recipient. I use a similar system to handle product reviews.

The Review DataObject looks like this

class Review extends DataObject
	static $db = array (
		'Date' => 'Date',
		'Name' => 'Text',
		'Email' => 'Text',
		'Title' => 'Text',
		'Location' => 'Text',
		'Rating' => 'Int',
		'Review' => 'HTMLText',
		'Approval' => 'Boolean'
	static $has_one = array (
		'Product' => 'Product',
		'ColorProduct' => 'ColorProduct'
	public function getCMSFields_forPopup()
		$ratingArray = array (
						  '1' => '1',
						  '2' => '2',
						  '3' => '3',
						  '4' => '4',
						  '5' => '5'
		return new FieldSet(
			new CheckboxField('Approval'),
			new CalendarDateField('Date'),
			new TextField('Name'),
			new EmailField('Email'),
			new TextField('Title'),
			new TextField('Location'),
			new DropdownField('Rating','Rating',$ratingArray),
			new TextareaField('Review')


While the ReviewForm on the Product DataObject looks like this

function UserProductReviewForm() {
      // Create fields
      $fields = new FieldSet(
							 new TextField('Name','Name:'),
							 new EmailField('Email','E-Mail Address:'),
							 new OptionsetField('Rating','Rating',array(
																		'1' => '1',
																		'2' => '2',
																		'3' => '3',
																		'4' => '4',
																		'5' => '5',
							 new TextField('Title','Review Title:'),
							 new TextareaField('Review'),
							 new HiddenField('ProductID', '', $this->ID),
							 new HiddenField('ProductName','',$this->Title)
      // Create actions
      $actions = new FieldSet(
         new FormAction('doReview', 'Submit')
		$form = new Form($this, 'UserProductReviewForm', $fields, $actions);
		$protector = SpamProtectorManager::update_form($form);
		if($protector) $protector->setFieldMapping('Name', 'Email', 'Title', 'Review');
	return $form;

function doReview($data, $form) {
      $review = new Review();
	  //Set data
	  $From = "";
	  $To = "";
	  $Subject = "New Review for " . $data['ProductName'];
	  $email = new Email($From, $To, $Subject,$body);
	  //set template
	  //populate template
	  //send mail
	  //return to submitted message
	  Director::redirect(Director::baseURL(). "thank-you-for-your-review/");
	  //return $this->Mailto;

You could also just replace the whole set/populate template section buy pushing the form fields into the $body


Community Member, 151 Posts

15 July 2011 at 4:18am

thanks very much... do you do any freelance? we are interested in getting a silverstripe developer on board. Cheers


Community Member, 545 Posts

15 July 2011 at 5:30am

Haha I do, but I have an impending baby on the way and I don't want to commit to any major projects until I know how it will big wrench it'l throw in my freelance time :)

But if you need some advice, feel free to contact me.