Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate a simple form
    primarykey
    data
    text
    <p>Just want to create a simple contact form in Symfony 2.1. How? </p> <p>ContactForm.php:</p> <pre><code>namespace frontend\mainBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; class ContactForm extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder-&gt;add('subject', 'textarea'); $builder-&gt;add('email', 'email'); $builder-&gt;add('message', 'textarea'); } public function getName() { return 'contact'; } } </code></pre> <p>DefaultController.php</p> <pre><code>namespace frontend\mainBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use mylib\DataFormatChecker; use frontend\mainBundle\Form\ContactForm; use Symfony\Component\HttpFoundation\Request; class DefaultController extends Controller { public function contactAction(Request $request) { $task = array(); $form = $this-&gt;createFormBuilder(new ContactForm(), $task); if ($request-&gt;getMethod() == 'POST') { $form-&gt;bindRequest($request); if ($form-&gt;isValid()) { // perform some action, such as saving the task to the database //return $this-&gt;redirect($this-&gt;generateUrl('task_success')); } } return $this-&gt;render('frontendmainBundle:Default:contact.html.php', array( 'form' =&gt; $form-&gt;createView() )); } } </code></pre> <p>Error: Declaration of frontend\mainBundle\Form\ContactForm::buildForm() must be compatible with Symfony\Component\Form\FormTypeInterface::buildForm(Symfony\Component\Form\FormBuilderInterface $builder, array $options) in line 8 in ContactForm.php.</p> <p>What is wrong?</p> <p>Sorry, used to symfony 1.4</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload