Skip to content

Instantly share code, notes, and snippets.

@ss23
Created April 9, 2013 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ss23/5343445 to your computer and use it in GitHub Desktop.
Save ss23/5343445 to your computer and use it in GitHub Desktop.
<?php
class HomePage extends Page {
}
class HomePage_Controller extends Page_Controller {
static $allowed_actions = array('BuyForm', 'doBuy', 'complete', 'failed', 'beforeBuy');
public function BuyForm() {
$fields = new FieldList(
new FieldGroup('Customer Details',
TextField::create('FirstName', 'First name')->setAttribute('required', true),
new TextField('LastName', 'Last name'),
new EmailField('Email', 'e-mail Address'),
new PhoneNumberField('Phone')
),
new FieldGroup('Terms & Conditions',
new LiteralField('TC', '<div class="typography">' . $this->getActiveDeal()->TermsAndConditions . '</div>'),
new CheckboxField('TCAgree', 'I accept the terms & conditions')
),
new HiddenField('DealID', 'DealID', $this->getActiveDeal()->ID)
);
$actions = new FieldList(
new FormAction('doBuy', 'Next'),
new LabelField('note', 'You will be directed to a secure DPS page, then returned to this website.')
);
$required = new RequiredFields(array('FirstName', 'LastName', 'Email', 'Phone', 'TCAgree', 'DealID'));
$form = new Form($this, __FUNCTION__, $fields, $actions, $required);
$form->loadDataFrom($this->request->postVars());
return $form;
}
public function doBuy($data, $form) {
var_dump($form->validate());
die('called');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment