Last active
September 11, 2016 09:04
-
-
Save sheadawson/e584b0771f6b124701b4 to your computer and use it in GitHub Desktop.
SilverStripe Blocks - Block with contact form example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class='$CSSClasses'> | |
<h3>$Name</h3> | |
$ContactForm | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you get the HTTP GET parameter within the controller or the template? Like the
?contacted=1
part?