Created
April 6, 2015 15:38
-
-
Save muskie9/0e4e180e4751ef323178 to your computer and use it in GitHub Desktop.
This file contains 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 Page_Controller extends ContentController { | |
private static $allowed_actions = array( | |
'MyForm' | |
); | |
public function MyForm() { | |
$fields = new FieldList( | |
TextField::create('Name'), | |
EmailField::create('Email') | |
); | |
$actions = new FieldList( | |
FormAction::create('doSubmitForm', 'Submit') | |
); | |
$form = new Form($controller, 'MyForm', $fields, $actions); | |
return $form | |
} | |
public function doSubmitForm($data, $form) { | |
// At this point, RequiredFields->validate() will have been called already, | |
// so we can assume that the values exist. Say we want to make sure that email hasn't already been used. | |
$check = Member::get()->filter('Email', $data['Email'])->first(); | |
if($check) { | |
$form->addErrorMessage('Email', 'This email already exists', 'bad'); | |
return $this->redirectBack(); | |
} | |
$form->sessionMessage("You have been added to our mailing list", 'good'); | |
return $this->redirectBack(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment