Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:30:54+00:00 2026-06-07T15:30:54+00:00

Is it possible to make a single form type to handle both of the

  • 0

Is it possible to make a single form type to handle both of the below scenarios?

I’m working on an application where a “normal” user (e.g. ROLE_USER) can perform a task by filling out a form. When the record gets created, he is linked to the event table. Additionally the ROLE_ADMIN user can link people on their behalf (using the same form with an additional ‘user’ field), selecting the user from a list of users.

At the moment I have an “eventType” and an “eventAdminType” with 98% code duplication. I’ve read about transformers and also form events, but I’m not entirely sure how I can adapt them to my needs.

Form code of “eventType”:

$builder
    ->add(
        'reservedSlots', 'choice', array(
            'choices'   => array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5'),
            'required'  => true,
        )
    )

Form code of “eventAdminType”:

$builder
    ->add('user')
    ->add(
        'reservedSlots', 'choice', array(
            'choices'   => array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5'),
            'required'  => true,
        )
    )

Entity code:

class EventUser
{
...
/**
 * @ORM\OneToOne(targetEntity="User")
 * @var type
 */
private $user;
...
// all the other fields
/**
 *
 * @ORM\Column(type="integer")
 */
private $reservedSlots

How would I create a single form type the above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:30:56+00:00Added an answer on June 7, 2026 at 3:30 pm

    You could create form type classes for both of your types and have one extend another:

    namespace Acme\Bundle\DemoBundle\Form;
    
    use Symfony\Component\Form\AbstractType;
    use Symfony\Component\Form\FormBuilder;
    
    class EventType extends AbstractType
    {
        public function buildForm(FormBuilder $builder, array $options)
        {
            // some code
        }
    }
    

    namespace Acme\Bundle\DemoBundle\Form;
    
    use Symfony\Component\Form\FormBuilder;
    
    class EventAdminType extends EventType
    {
        public function buildForm(FormBuilder $builder, array $options)
        {
            parent::buildForm($builder, $options);
    
            // fields for the admin form
        }
    }
    

    Here’s some additional info about creating form classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to make a Telerik RadEditor single-line entry only? For example, in
Is it possible to (and if so, how do I) make a single program
Is it possible make some handler that will do something when user shutdown computer
I need to make an application in .NET CF with different/single forms with a
I was wondering if its possible to make a single comboBox not visible or
Possible Duplicates: Make a wizard like application in Android Pattern one activity, multiple views.
In a Struts 1.x application, I have a form with a simple single-selection html:select
Is it possible to make a regular expression to match everything within single brackets
I would like to make a single Android app for multiple Android versions (possibly
Is it possible make an activity, that will lock the android device? That device

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.