opifer / form-bundle
Opifer Form Bundle
Installs: 1 188
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 2
Type:symfony-bundle
Requires
- php: >=5.4
- doctrine/doctrine-bundle: ~1.2
- doctrine/orm: ~2.2,>=2.2.3
- gedmo/doctrine-extensions: ~2.3
- opifer/eav-bundle: ~0.1
- symfony/swiftmailer-bundle: ~2.3
- symfony/symfony: ~2.3
- twig/extensions: ~1.2
Requires (Dev)
- mockery/mockery: ~0.9
- phpunit/phpunit: ~4.2
- symfony/phpunit-bridge: ~2.7
README
Opifer FormBundle
Installation
Add OpiferForm to your composer.json:
$ composer require opifer/form-bundle "~0.1"
Register the bundle in app/AppKernel.php
:
public function registerBundles() { $bundles = array( // ... new Opifer\EavBundle\OpiferEavBundle(), new Opifer\FormBundle\OpiferFormBundle() ); }
Install the OpiferEavBundle
according to its documentation.
Extend the Form & Post models;
namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Opifer\FormBundle\Model\Form as BaseForm; /** * @ORM\Entity() * @ORM\Table(name="form") */ class Form extends BaseForm { }
namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Opifer\EavBundle\Model\EntityInterface; use Opifer\FormBundle\Model\Post as BasePost; /** * @ORM\Entity() * @ORM\Table(name="post") */ class Post extends BasePost implements EntityInterface { }
Define these in the config along with your admin email:
opifer_form: from_email: noreply@yourcompany.com form: class: AppBundle\Entity\Form post: class: AppBundle\Entity\Post
To be able to manage and use your forms, add some routes to your app/config/routing.yml
:
opifer_form: resource: "@OpiferFormBundle/Resources/config/routing.yml" opifer_form_admin: resource: "@OpiferFormBundle/Resources/config/routing_admin.yml" prefix: /admin
Usage
Once you created your forms in your admin panel, you might want to display them on the frontend. To do this, you'd have to create a controller action that retrieves the form and displays it on the frontend
namespace AppBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; class PageController extends Controller { public function contactAction() { $form = $this->get('opifer.form.form_manager')->getRepository()->find(1); return $this->render('Page/contact.html.twig', array( 'form' => $form )); } }
{# app/Resources/views/Page/contact.html.twig #} {% set form = create_form_view(form) %} {{ form_start(form) }} {{ form_widget(form) }} <input type="submit" value="save"> {{ form_end(form) }}