Skip to content

Instantly share code, notes, and snippets.

@hailwood
Created February 17, 2016 03:02
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 hailwood/f92d4d0f7702179d6c95 to your computer and use it in GitHub Desktop.
Save hailwood/f92d4d0f7702179d6c95 to your computer and use it in GitHub Desktop.
<?php
class CustomModelAdmin extends ModelAdmin {
public function SettingsForm()
{
if ($this->request->isPOST()) {
$form = $this->getSubsectionForm(); //returns from CMSForm::create($this, 'SettingsForm', ...)
$form->loadDataFrom($this->request->postVars());
foreach ($this->request->postVars() as $name => $val) {
if (strpos($name, 'action_') === 0) {
$actionName = substr($name, strlen('action_'));
if ($this->hasMethod($actionName)) {
$this->{$actionName}($form->getData(), $form);
}
}
}
return $form->forTemplate();
} else {
return $this->getSubsectionForm();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment