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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:00:47+00:00 2026-05-27T06:00:47+00:00

I have a form where the user enters data. Then, when they click submit,

  • 0

I have a form where the user enters data. Then, when they click submit, this data will be saved to the database.

The only thing is, it doesn’t do this. What does happen, is that when submit is clicked, the page reloads and all the data entered in the form will still be displayed. I go to check the database, and the records haven’t been updated.

There are no errors, but according to the profiler there are three SQL statements run when the page is loaded. All three of these are SELECT statements, not one INSERT statement there.

Here is the code for the page in the controller (including the “INSERT” statement):

    public function addAction(Request $request)
{   

    $pageadd = new Content();
    $form = $this->createForm(new PageAdd(), $pageadd);

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

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getEntityManager();

            $em->persist($pageadd);
            $em->flush();

            return new Response('Created page id '.$pageadd->getId());

        }
    }

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

}

Here is the code for the form (I’ve omitted some of the fields for space reasons. But they are all identical):

<form action="{{ path('ShoutAdminBundle_adminpageaddpost') }}" method="post" {{ form_enctype(form) }} class="blogger">

    <p class="row">
        {{ form_label(form.id, 'ID*', { 'attr': {'class': 'title'} }) }}
        {{ form_errors(form.id) }}
        {{ form_widget(form.id, { 'attr': {'class': 'textfield'}}) }}
    </p>
    <p class="row">
        {{ form_label(form.title, 'Title*', { 'attr': {'class': 'title'} }) }}
        {{ form_errors(form.title) }}
        {{ form_widget(form.title, { 'attr': {'class': 'textfield'}}) }}
    </p>

    <p class="row">
        <input type="submit" value="Save This Page" class="savebutton" />
    </p>
</form>

If you need any more code I will provide them. I think these two bits of code is where the problem lies though.

Cheers!

  • 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-27T06:00:48+00:00Added an answer on May 27, 2026 at 6:00 am

    You must fill the entity before the persist, I give you an example:

    public function saveAction(Request $request)
    {
        if ($request->getMethod() == 'POST') {
            // EntityManager
            $em = $this->getDoctrine()->getEntityManager();
    
            // New entity
            $registration = new Customer();
    
            // Build the form
            $form = $this->createFormBuilder()
            ->add('name', 'text')
            ->add('country', 'text')
            ->add('email', 'email')
            ->add('certificate', 'text')
            ->add('provider', 'entity', array(
                  'class' => 'YourCustomBundle:Partner',
            ))
            ->getForm();
    
            // Populate
            $form->bindRequest($request);
    
            // Check
            if($form->isValid()) {
                // Fill the entity
                $registration->setName($form['name']->getData());
                $registration->setCountry($form['country']->getData());
                $registration->setEmail($form['email']->getData());
                $registration->setCertificate($form['certificate']->getData());
                $registration->setProvider($form['provider']->getData());
                $em->persist($registration);
                $em->flush();
            }   
    
        }
        return $this->render('YourCustomBundle:Default:index.html.twig',array(
                'form' => $form->createView(),
        ));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form a user can enter their name, then it will add
I have a form which user enters data and upload a picture, when user
I have a form that performs calculations live as the user enters data. However,
i have a form which user enters some data, could be checkboxes, radio buttons,
I have a form where user enters data about a new inventory item (id,title,
I have a delete form wherein the user will enter the pnum to be
i have a form where user enters an ad start time and an ad
I have a form that requires a physical address. Once the user enters the
I have a User controller and User model. This model and associated database table
I am designing a database app, and have a form which populates with data

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.