Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SilverStripe Blocks - Block with contact form example
<?php
class ContactBlock extends Block {
/**
* Template accessor for the form
**/
public function ContactForm(){
return $this->getController()->ContactForm();
}
}
class ContactBlock_Controller extends Block_Controller {
private static $allowed_actions = array(
'ContactForm'
);
public function ContactForm(){
$fields = FieldList::create(array(
TextField::create('Name'),
EmailField::create('Email'),
TextField::create('Organisation'),
TextAreaField::create('Message')
));
$actions = FieldList::create(
FormAction::create('submit', 'Send Enquiry')
);
return Form::create($this, 'ContactForm', $fields, $actions);
}
public function submit($data, $form){
// process form data as usual
// ...
// redirect
return $this->redirect($this->pageLink() . '?contacted=1');
}
}
<div class='$CSSClasses'>
<h3>$Name</h3>
$ContactForm
</div>
@hohl

This comment has been minimized.

Copy link

commented Sep 11, 2016

How do you get the HTTP GET parameter within the controller or the template? Like the ?contacted=1 part?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.