Skip to content

Instantly share code, notes, and snippets.

@sheadawson
Last active September 11, 2016 09:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sheadawson/e584b0771f6b124701b4 to your computer and use it in GitHub Desktop.
Save sheadawson/e584b0771f6b124701b4 to your computer and use it in GitHub Desktop.
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
Copy link

hohl 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