Skip to content

Instantly share code, notes, and snippets.

@panbanda
Created March 20, 2012 22:22
Show Gist options
  • Save panbanda/2141902 to your computer and use it in GitHub Desktop.
Save panbanda/2141902 to your computer and use it in GitHub Desktop.
Form Submission Handler for Base Controller
<?php
/**
* Check for form submission with a csrf check
*/
private function __form_submission()
{
if ($post = Input::post())
{
$token = Arr::get($post, 'csrf');
$action = Arr::get($post, 'action');
if (! Security::check($token) OR $action === NULL) return FALSE;
$method = preg_replace('/[^a-zA-Z0-9_]+/', '', 'do_'.$action);
if (method_exists($this, $method))
{
call_user_func(array($this, $method));
}
}
}
// This will call function do_{$action}()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment