Am trying to add new register fields in zfcuser moudle in register. I have problem bcs new fields not rendered in register.phtml
What i do:
First i create new User entity in my custom module and extend \ZfcUser\Entity\User, and add new properties protected $first_name and put getter method.
Second, i change user_entity_class' => 'MyModule\Entity\User in config.
Third, i create custom form class where i extend \ZfcUser\Form\Register where i create two methods __constructor($name,RegistrationOptionsInterface $options), second init(). THis look like this:
// Module/src/Mymod/Form
class ClientRegisterForm extends \ZfcUser\Form\Register
{
public function __construct($name, RegistrationOptionsInterface $options)
{
parent::__construct($name, $options);
}
/**
* {@inheritDoc}
*/
public function init(){
$this->add(array(
'name' => 'first_name',
'options' => array(
'label' => 'First name',
),
'attributes' => array(
'type' => 'text'
),
));
}
And i register this like sercice in module:
public function getServiceConfig()
{
return array(
'factories' => array(
'clientRegisterForm' => function($sm) {
$clientRegisterForm = new ClientRegisterForm(null, array());
return $clientRegisterForm;
}
)
);
}
So problem is bcs zfcuser dont know nothing about new field. Loop list just default fields. How to notify zfcuser module about new field in this way?
register.phtml
<?php foreach ($form as $element): ?>
<?php echo $this->formInput($element) . $this->formElementErrors($element) ?>
<?php endforech; ?>
Typically you'll first modify your module.config.php so that it reflects your zfcuser_entity properly.
Then in your bootstrap you need to listen to attach to ZfcUser\Form\RegisterFilter, ZfcUser\Form\Register (both init) to modify the form.
Lastly, also in your bootstrap, you attach to the 'register' event on the 'zfcuser_user_service' event manager.
I've got a full on post that walks through the minutia here: http://circlical.com/blog/2013/4/1/l5wftnf3p7oks5561bohmb9vkpasp6
Nowadays, I simply roll my own User entities, Auth service in conjunction with my own Login, Reg forms and so forth. Originally I liked the combination of ZfcUser and BjyAuthorize -- but BjyAuthorize + custom has been a better treat!
Good luck man.