Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Formbundle Laravel Package

alpixel/formbundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer:

    composer require alpixel/formbundle
    

    Enable it in AppKernel.php (Symfony 2.x):

    new Alpixel\FormBundle\AlpixelFormBundle(),
    
  2. First Use Case Create a form type extending Alpixel\FormBundle\Form\Type\BaseFormType:

    use Alpixel\FormBundle\Form\Type\BaseFormType;
    
    class MyFormType extends BaseFormType
    {
        public function getName()
        {
            return 'my_form';
        }
    
        public function buildForm(FormBuilderInterface $builder, array $options)
        {
            $builder->add('name', 'text');
            $builder->add('submit', 'submit');
        }
    }
    
  3. Register the Form Add the form type to your services (Symfony 2.x):

    # app/config/services.yml
    services:
        my_form.type:
            class: AppBundle\Form\Type\MyFormType
            tags:
                - { name: form.type, alias: my_form }
    
  4. Use in Controller

    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    
    class MyController extends Controller
    {
        public function indexAction(Request $request)
        {
            $form = $this->createForm('my_form');
            // ...
        }
    }
    

Implementation Patterns

Common Workflows

  1. Dynamic Form Fields Leverage BaseFormType to dynamically add fields based on runtime logic:

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        if ($options['dynamic_field']) {
            $builder->add('dynamic_field', 'text');
        }
    }
    
  2. Form Events Use Symfony’s form events (e.g., PRE_SET_DATA, POST_SUBMIT) for validation or transformations:

    $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
        $data = $event->getData();
        // Modify data before form population
    });
    
  3. Reusable Form Components Create modular form types for reuse (e.g., AddressFormType, UserProfileFormType).

  4. Integration with Doctrine Bind forms to entities via add() with entity class:

    $builder->add('user', 'entity', [
        'class' => 'AppBundle\Entity\User',
        'property' => 'name',
    ]);
    

Integration Tips

  • Symfony 3/4+ Note: This bundle is outdated (last release 2017). For modern Laravel/Symfony, consider alternatives like:
    • Symfony’s built-in FormComponent (Symfony 4+).
    • Laravel’s Form packages (e.g., laravelcollective/html).
  • Legacy Projects: If stuck with Symfony 2.x, pair with FOSUserBundle for user management or StofDoctrineExtensions for advanced form fields.

Gotchas and Tips

Pitfalls

  1. Outdated Dependencies

    • Requires Symfony 2.8+ but lacks updates. Test thoroughly in isolated environments.
    • PHP 5.3+ support is obsolete; upgrade to PHP 7.4+ if possible.
  2. Limited Documentation

    • No active maintainer or community. Rely on Symfony’s core form documentation for gaps.
  3. Form Type Registration

    • Ensure form.type tags are correctly configured in services.yml or as annotations.
  4. CSRF Protection Enable Symfony’s CSRF protection in forms:

    {{ form_start(form, { attr: { 'data-csrf-token': app.session.token } }) }}
    

Debugging Tips

  • Form Errors: Use {{ dump(form.errors) }} in Twig to inspect validation issues.
  • Data Binding: Check PRE_SET_DATA events for entity hydration problems.
  • Logs: Enable Symfony’s profiler (app/console debug:config) to trace form lifecycle.

Extension Points

  1. Custom Validation Add constraints via annotations or callbacks:

    use Symfony\Component\Validator\Constraints as Assert;
    
    $builder->add('email', 'email', [
        'constraints' => new Assert\NotBlank(),
    ]);
    
  2. Override Templates Customize form themes in config.yml:

    twig:
        form_themes:
            - 'AlpixelFormBundle:Form:fields.html.twig'
    
  3. Event Subscribers Attach global form logic via FormEvents:

    $formFactory->addFormTypeExtension(new MyExtension(), 'my_form');
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc
animalyoung/laravel-influxdb
onix-solutions/sms-telera
lonely-lights/prosetta
oxygen/data
oxygen/core
jengo/base
xiloryx/log-collector
a21ns1g4ts/filament-stripe
la-php/laravel-admin
artisan-build/community-prompts
vleroy/smart
ayles-software/laravel-australian-public-holidays
cboxdk/laravel-id-spatie
cboxdk/laravel-id-billing
cboxdk/laravel-id-billing-bridge
simple-as-fuck/php-performance-log