Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- abstract class FormHandler extends Nette\Object
- {
- public function attach(Form $form)
- {
- $that = $this;
- if (method_exists($this, 'handleSuccess')) {
- $form->onSuccess[] = function (Form $form) use ($that) {
- if (!$form->isValid()) return;
- $that->handleSuccess($form->getValues());
- };
- }
- if (method_exists($this, 'handleError')) {
- $form->onError[] = function (Form $form) use ($that) {
- $that->handleError($form->getValues());
- };
- }
- }
- public function attachButton(SubmitButton $button)
- {
- $that = $this;
- if (method_exists($this, 'handleClick')) {
- $button->onClick[] = function (SubmitButton $button) use ($that) {
- $that->handleClick($form->getValues());
- };
- }
- if (method_exists($this, 'handleError')) {
- $button->onInvalidClick[] = function (SubmitButton $button) use ($that) {
- $that->handleError($form->getValues());
- };
- }
- }
- }
- class RegistrationHandler extends FormHandler
- {
- public $onFoo = array();
- public $onBar = array();
- public function handleSuccess($values) { ... }
- }
- $form = new Form;
- $handler = new RegistrationHandler();
- $handler->attach($form);
- $handler->attachButton($form->addSubmit('send', "Odeslat"));
Advertisement
Add Comment
Please, Sign In to add comment