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

  • Home
  • SEARCH
  • 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 9030599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:31:50+00:00 2026-06-16T07:31:50+00:00

Just want to create a simple contact form in Symfony 2.1. How? ContactForm.php: namespace

  • 0

Just want to create a simple contact form in Symfony 2.1. How?

ContactForm.php:

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->add('subject', 'textarea');
        $builder->add('email', 'email');
        $builder->add('message', 'textarea');
    }
    public function getName()
    {
        return 'contact';
    }

}

DefaultController.php

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->createFormBuilder(new ContactForm(), $task);  
        if ($request->getMethod() == 'POST') {
        $form->bindRequest($request);

        if ($form->isValid()) {
            // perform some action, such as saving the task to the database

            //return $this->redirect($this->generateUrl('task_success'));
        }
    }
    return $this->render('frontendmainBundle:Default:contact.html.php', array(
        'form' => $form->createView()
    ));
    }
}

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.

What is wrong?

Sorry, used to symfony 1.4

  • 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-16T07:31:51+00:00Added an answer on June 16, 2026 at 7:31 am

    The error has nothing to do with symfony, actually. It occurs because declaration of buildForm function does not match with that of base class (AbstractType). The first parameter of buildForm must be an instance of FormBuilderInterface whereas your first parameter is instance of FormBuilder

    // ...
    use Symfony\Component\Form\FormBuilderInterface;
    
    class ContactForm extends AbstractType
    {
        public function buildForm(FormBuilderInterface $builder, array $options)
        // ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I create my own login form on frontend? I don’t just want
i want create one simple windows form ,it just contain Editcontrol(textbox),Static Edit(label),Button (Name of
I'm looking for as simple way to create an identity set. I just want
I used this tutorial as a guide to create a simple contact form. I
Hi there I just want to create a simple golang applications, which posts a
hi all i just want to create a simple jsp tag such as :
I am using Rails 3. I just want to create a simple javascript object
I've created a simple class and got a little problem: I just want to
I just want to understand why I cannot create a protected enum on C#?
For our deployments, I just want to drop the existing stored proc, then re-create

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.