Giter Site home page Giter Site logo

marwenmdoukhi / embed-collection-of-forms Goto Github PK

View Code? Open in Web Editor NEW

This project forked from konshensx16/embed-collection-of-forms

0.0 1.0 0.0 49 KB

Heavily commented project which includes a demo using collection of forms in symfony 3

License: MIT License

JavaScript 4.76% PHP 93.16% HTML 2.09%

embed-collection-of-forms's Introduction

Embed Collection Of Forms

Here's a link to a youtube video explaining this repository: https://youtu.be/nLy7dIQPCUI

Check the timestamps in the description

What this repository contains

  • Configuring your symfony application to use SQLite instead of Mysql
  • Creating Two entities: User and Exp (means Experience) which are related with the following relationship:
    • Exp.php
      • @ORM\ManyToOne(targetEntity="User", inversedBy="exp")
      • @ORM\JoinColumn(name="user_id", referencedColumnName="id")
    • User.php:
      • @ORM\OneToMany(targetEntity="Exp", mappedBy="user", cascade={"persist"})
      • Also don't forget to set the user in addExp function:
        public function addExp(\AppBundle\Entity\Exp $exp)
          {
              $this->exp[] = $exp;
              // setting the current user to the $exp,
              // adapt this to whatever you are trying to achieve
              $exp->setUser($this);
              return $this;
          }
        
  • Next up, creating the forms from the command-line, pretty straight forward
    • ExpType.php:
      • Nothing special about this file
    • User.php:
      public function buildForm(FormBuilderInterface $builder, array $options)
         {
             $builder
                 ->add('fullname')
                 // this is the embeded form, the most important things are highlighted at the bottom
                 ->add('exp', CollectionType::class, [
                     'entry_type' => ExpType::class,
                     'entry_options' => [
                         'label' => false
                     ],
                     'by_reference' => false,
                     // this allows the creation of new forms and the prototype too
                     'allow_add' => true,
                     // self explanatory, this one allows the form to be removed
                     'allow_delete' => true
                 ])
                 // just a regular save button to persist the changes
                 ->add('save', SubmitType::class, [
                     'attr' => [
                         'class' => 'btn btn-success'
                     ]
                 ])
             ;
         }
      
  • Next, sending the form to the view and hadling the form submition
  • Creating the JavaScript file which does most of the work:
    • Please look up the file in the repository, i cannot put the code here because it's about 80 or 90 lines long
  • And finally persisting the data to the database

embed-collection-of-forms's People

Contributors

konshensx16 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.