Skip to content

Instantly share code, notes, and snippets.

@marchampson
Created February 19, 2013 11:56
Show Gist options
  • Save marchampson/4985199 to your computer and use it in GitHub Desktop.
Save marchampson/4985199 to your computer and use it in GitHub Desktop.
Add additional fields to zfcuser registation form
public function onBootstrap(MvcEvent $e)
{
$events = $e->getApplication()->getEventManager()->getSharedManager();
$events->attach('ZfcUser\Form\Register', 'init', function($e) {
$form = $e->getTarget();
$form->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'role',
'options' => array (
'label' => 'Select Role',
'value_options' => array (
'User' => 'User',
'Admin' => 'Admin',
'Hal9000' => 'Hal9000',
),
)
));
});
$events->attach('ZfcUser\Form\RegisterFilter', 'init', function($e) {
$filter = $e->getTarget();
// Do what's needed with the filter instance ($filter);
});
$this->sm = $e->getApplication()->getServiceManager();
$zfcServiceEvents = $this->sm->get('zfcuser_user_service')->getEventManager();
$zfcServiceEvents->attach('register', function($e) {
$form = $e->getParam('form');
$this->role = $form->get('role')->getValue();
});
$zfcServiceEvents->attach('register.post', function($e) {
$user = $e->getParam('user');
$sql = "update user set role = '$this->role' where user_id = ".$user->getId();
$adapter = $this->sm->get('Zend\Db\Adapter\Adapter');
$adapter->query($sql, Adapter::QUERY_MODE_EXECUTE);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment