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 6804971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:31:51+00:00 2026-05-26T19:31:51+00:00

In symfony 2, one can embed a controller in a template. For example, I

  • 0

In symfony 2, one can embed a controller in a template. For example, I might have a template for a blog post, but I can also embed a controller to a poll or a list of top articles in the side-bar of the template.

I am interested in embedding a controller that provides a poll. To do so, I have created a controller:

public function poll(Request $request)
{
    $task = new Poll();

    $form = $this->createFormBuilder($task)
        ->add('radio', 'one')
        ->add('radio', 'two')
        ->add('radio', 'three')
        ->getForm();

    if ($request->getMethod() == 'POST') {
        $form->bindRequest($request);

        if ($form->isValid()) {
            //save and show how many people voted for each option
        }
    }

    return $this->render('PollBundle:Default:new.html.twig', array(
            'form' => $form->createView(),
        ));

}

I can then embed this as a side bar item in my template:

<div id="sidebar">
    {% render "PollBundle:Poll:poll" %}
</div>

The problem now is this:
If I set the form action to be "", then if the poll was submitted, the request would go through the main controller which embeds the Poll controller. I can then use a hidden field to check if the poll was submitted using the poll form, then update the database and render the result. This then gets returned to the template of the main controller and all is good.

I would now like to use some AJAX to streamline the form submission for those who have javascript enabled. How can I go about doing this? Since the form action is set to "", the request would go through the main controller, render the template which then calls the Poll controller. But I would like to just return an AJAX response containing the votes casted for each item. In anycase, having to go through the main controller just to populate a poll using an AJAX request seesm to be quite wasteful too.

How should I go about doing this?

  • 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-05-26T19:31:52+00:00Added an answer on May 26, 2026 at 7:31 pm

    You can point the form to its own action that handles the post and, if it’s being requested through ajax then return the results or, if it’s reached through a normal request, redirect to the HTTP_REFERER ($this->get('request')->server->get('HTTP_REFERER')).

    If you don’t want to rely on the referer, you could also store the current URI in a session variable when rendering the poll (in the pollAction you’ve described above).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table and one of the columns can be null. In symfony,
We have FireSymfony that allows one to view the Symfony, PHP variables in a
im working on a symfony project and one of the things i have to
I use symfony 1.4.10 I have next situation: User can create Ads and he
In symfony 2.0, how to create a drop down list using one-to-one association in
am using the symfony's admin generator, in the new interface, i have one specific
I have some form, and one column have Entity type, but this entity have
I have a Symfony 1.2.4 application, taken and modified from the Symfony sandbox application
we using symfony 1.0. We have an module work with Propel objects. The sql-querys
at the moment i have a column user_id in the threads table cause one

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.