hi,

you could do something nasty like

if(!$this->getUser()->hasAttribute('user'))
        $tempSchema=$this->form->getWidgetSchema();
      unset($tempSchema ['mine'];
      $this->form->setWidgetSchema($tempSchema);
}

but this wouldn't be testable.

better solution is 
http://eatmymonkeydust.com/2009/08/symfony-forms-flexible-widgets-based-on-user-credentials/

Regards,
Christopher.

> -----Ursprüngliche Nachricht-----
> Von: symfony-users@googlegroups.com [mailto:symfony-
> us...@googlegroups.com] Im Auftrag von torok84
> Gesendet: Mittwoch, 8. September 2010 16:32
> An: symfony users
> Betreff: [symfony-users] Removing a field from a form in an action
> 
> Hi,
> 
> I have a form to select some search options. I have a field that I
> wanto to show only if the user is logged in. I want to do something
> like this:
> 
> if(!$this->getUser()->hasAttribute('user'))
>       unset($this->form->widgetSchema['mine']);
> 
> that doesn't work because widgetSchema is protected. Moreover doing
> this would leave a dangling validator for the 'mine' field. I
> undestand I can create a second form class without the 'mine' field,
> but it would be nice if I could simply unset a field.
> 
> Thanks
> Paolo
> 
> --
> If you want to report a vulnerability issue on symfony, please send it
> to security at symfony-project.com
> 
> You received this message because you are subscribed to the Google
> Groups "symfony users" group.
> To post to this group, send email to symfony-users@googlegroups.com
> To unsubscribe from this group, send email to
> symfony-users+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony-users?hl=en

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to