0

i am using ZFcuser with zendframework 2 and want to extend the registration form to enable me to add a radio field.

i followed the tutorial here

it works ok and i am able to render and obtain the values for imput tags. the problem comes when i try to render a radio button. it only renders one of the values.

here is my code:

   public function onBootstrap(MVCEvent $e)
    {
        $eventManager = $e->getApplication()->getEventManager();
        $em           = $eventManager->getSharedManager();
        $em->attach(
                'ZfcUser\Form\RegisterFilter',
                'init',
                function($e)
                {
                    $filter = $e->getTarget();

                    $filter->add(array(
                    'name' => 'accept',
                    'required' => FALSE
        ));           
                }
            );
            // custom form fields

            $em->attach(
                'ZfcUser\Form\Register',
                'init',
                function($e)
                {
                    /* @var $form \ZfcUser\Form\Register */
                    $form = $e->getTarget();
                    $form->add(
                        array(
                            'name' => 'username',
                            'options' => array(
                                'label' => 'Username',
                            ),
                            'attributes' => array(
                                'type'  => 'text',
                            ),
                        )
                    );


              $form->add(array(
                    'type' => 'Zend\Form\Element\radio',
                    'name' => 'terms',
                    'options' => array(
                        'label' => 'Accept Terms',
                        'value_options' => array(
                            '1' => 'Yes',
                            '0' => 'No',
                        ),
                    ),

                ));
                }
            );

            $zfcServiceEvents = $e->getApplication()->getServiceManager()->get('zfcuser_user_service')->getEventManager();

            $zfcServiceEvents->attach('register', function($e) {
                $form = $e->getParam('form');
                $user = $e->getParam('user');

the HTML

the html from this output only render 1 input tag; i.e

<input type="radio" value="" name="terms">

however, i need to render two radio buttons; one for the yes, and one for the no

does anyone have any ideas how to do this; i really appreciate your help

paul kendal23
  • 171
  • 2
  • 3
  • 14

1 Answers1

1

This is a limitation of the current ZfcUser(v. 1.x), but is something that will be fixed in the coming version(v. 2.x). In the meantime: overwrite the standard view with your own.

Danielss89
  • 863
  • 1
  • 11
  • 17
  • Hi Danielss89. thank you for your responce. i am not clear how i will go about overwriting it though. i mean, i know how to over-right the standard view. but if i am to overwrite the standard view and manually insert the radio buttons, how will i prevent the module class from rendering the radio input bar. In other words i want to still use the module class to extend the ZFuUser but then prevent it from actually rendering the form. Is this possible – paul kendal23 Jun 08 '14 at 13:58
  • You can overwrite the view by just creating the viewfile: `view/zfc-user/user/register.phtml` in your module – Danielss89 Jun 14 '14 at 10:07
  • aaaaa that was crazy! I tried so many different things. Studied the whole zfcuser to see what I have done wrong! For God shake... I couldn't make a selectbox or radiobox in the most popular zf2 module! Write this damn limitation somewhere! Just write it... – Nikitas Jul 20 '14 at 14:49