0

I am using Zendframework 2 with ZfcUser and ZfcUserDoctrineORM. I extended the normal user with some additional information.

Now i want to adapt the registerForm. Therefor i created this form in the ZfcUser\Form folder:

class UserRegister extends ZfcUser\Form\Register {
  public function init(){
    $this->add(array(
        'name' => 'firstName',
        'options' => array(
            'label' => 'First Name',
        ),
        'attributes' => array(
            'type' => 'text'
        ),
    ));

    $this->add(array(
        'name' => 'name',
        'options' => array(
            'label' => 'Last Name',
        ),
        'attributes' => array(
            'type' => 'text'
        ),
    ));
  }
}

In the Next step I changed adapted the getServiceConfig() function in the Module.php in the ZfcUser folder:

'zfcuser_register_form' => function ($sm) {
                $options = $sm->get('zfcuser_module_options');
                $form = new Form\UserRegister(null, $options);
                //$form->setCaptchaElement($sm->get('zfcuser_captcha_element'));
                $form->setInputFilter(new Form\RegisterFilter(
                    new Validator\NoRecordExists(array(
                        'mapper' => $sm->get('zfcuser_user_mapper'),
                        'key'    => 'email'
                    )),
                    new Validator\NoRecordExists(array(
                        'mapper' => $sm->get('zfcuser_user_mapper'),
                        'key'    => 'username'
                    )),
                    $options
                ));
                return $form;
            },

When calling the register url this error message is shown:

Fatal error: Cannot redeclare class UserRegister in C:\xampp\htdocs\THWDiver\vendor\zf-commons\zfc-user\src\ZfcUser\Form\UserRegister.php on line 24

What am I making wrong?

Iceman
  • 321
  • 1
  • 6
  • 21
  • Could you show the *complete* code of the `UserRegister.php` ? It seems that there is something missing (the namespace). Also, it is not recommended that you put code into the `ZfcUser` module itself. It is easily possible to extend code from the `ZfcUser` module, and use that code instead of editing the code of `ZfcUser` and thereby making upgrades a lot harder. – kokx Jan 13 '13 at 22:38
  • Thanks for your help. I fixed the "use" part of the file. How can i extend the ZfcUser module? – Iceman Jan 15 '13 at 09:35
  • I think that would be worth a separate question. – kokx Jan 15 '13 at 10:23
  • 1
    As a side note, It is not recommended at all to modify the zfcuser 's base code, rather you could override the service factory named "zfcuser_register_form" in your own module. – TheFuquan Dec 04 '15 at 19:06

2 Answers2

0

Realize this is an old question, but just stumbled onto it. You need to edit your Entity module's bootstrap and attach to 'ZfcUser\Form\Register' at 'init'.

I've got a blog article here that details the solution in depth: http://circlical.com/blog/2013/4/1/l5wftnf3p7oks5561bohmb9vkpasp6

Hope it helps you!

Saeven
  • 2,280
  • 1
  • 20
  • 33
0

I think that the answer is to override the service factory "zfcuser_register_form" and inside of it declare your own RegisterForm.

Dani Tome
  • 473
  • 1
  • 5
  • 16