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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:20:43+00:00 2026-06-02T23:20:43+00:00

I am just starting out with Symfony2 . Rather than having to learn twig,

  • 0

I am just starting out with Symfony2 . Rather than having to learn twig, I decided to implement my forms in php instead. I followed the instructions in The Book, as follows:

in the controller:

public function editAction($id)
{
    $em = $this->getDoctrine()->getEntityManager();

    $entity = $em->getRepository('MyBundle:MyEntity')->find($id);

    if (!$entity) {
        throw $this->createNotFoundException('Unable to find MyEntity entity.');
    }

    $editForm = $this->createForm(new MyEntityType(), $entity);
    $deleteForm = $this->createDeleteForm($id);

    return $this->render('MyBundle:MyEntity:edit.html.php' array(
        'entity'      => $entity,
        'edit_form'    => $editForm->createView(),
        'delete_form'  => $deleteForm->createView()
    ));
}

and in edit.html.php:

<form action="<?php echo $view['router']->generate('myentity_update', array('id'=>$entity->getId()))?>" method="post" <?php echo $view['form']->enctype($editForm) ?>>

   <?php echo $view['form']->widget($editForm)?>

  <p>
    <button type="submit">Save Changes</button>
  </p>
</form>
<ul class="record_actions">
<li>
    <a href="<?php $view['router']->generate('myentity') ?>">
        Back to the list
    </a>
</li>
<li>
    <form action="<?php $view['router']->generate('myentity_delete', array('id'=>$entity->getId()) ) ?>" method="post">
        <?php echo $view['form']->widget($deleteForm)?>
        <button type="submit">Delete</button>
    </form>
</li>

when I try to display the form I get error:
Notice: Undefined variable editForm

As far as I’m aware, I have followed the instructions exactly as they are given in The Book. I have tried replacing $editForm with $form in the action and template or replacing $editForm with edit_form in the template – needless to say, neither of these worked.

I would very much appreciate any suggestions as to what I should try next (or I may have to resign myself to learning twig, as at least the instructions for that seem to be correct).

  • 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-02T23:20:45+00:00Added an answer on June 2, 2026 at 11:20 pm

    You pass your variable to your view as edit_form (the array keys are the names of the variables to use in the view):

    return $this->render('MyBundle:MyEntity:edit.html.php' array(
        'entity'      => $entity,
        'edit_form'    => $editForm->createView(),
        'delete_form'  => $deleteForm->createView()
    ));
    

    but you reference it in your view as $editForm:

    <form action="<?php echo $view['router']->generate('myentity_update',
        array('id'=>$entity->getId()))?>" method="post" <?php echo $view['form']->enctype($editForm) ?>>
    

    Decide on the same approach for both (edit_form vs editForm), and you should be good. Eg 'edit_form' becomes $edit_form in the view, and similarly for 'editForm' becoming $editForm.

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

Sidebar

Related Questions

Just starting out to program in python and I'm having the following issue. I
So I am just starting out developing PHP web applications and have finished setting
I am just starting out with RoR, and I'm having some problems. I'm using
I'm just starting out with node.js, express and ejs. And I'm having a hard
I'm just starting out with WCF web services, and I'm having a really hard
I'm just starting out with Linq to NHibernate and having troubles with a pretty
Just starting out with OOP in PHP and in general. From what I have
I am just starting out with node.js v.0.6.2 and Mac OSX Lion, and followed
Just starting out with subversion, have set up repos for 3 current projects and
Just starting out, this should be a simple one but I haven't been able

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.