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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:19:20+00:00 2026-06-14T08:19:20+00:00

I’m implementing rest API using FOSRestbundle. Now say for POST request i’m getting request

  • 0

I’m implementing rest API using FOSRestbundle. Now say for POST request i’m getting request parameters properly like:

Symfony\Component\HttpFoundation\ParameterBag Object
(
    [parameters:protected] => Array
        (
            [rank] => 12
            [city] => 1345
            [comment]=> 'safd'
        )

)

My post action code is :

/**
 * @Rest\View
 */   
public function newAction(){

    $rank= new Rank();       
    $form = $this->createForm(new RankType(), $rank);
    $form->bind($this->getRequest());
    if ($form->isValid()) {
      //.  $user->flush();

      $em = $this->getDoctrine()->getManager();
      $em->persist($rank);
      $em->flush();
      $response = new Response();
      $response->setStatusCode($statusCode);
      $view = View::create()  
        ->setData($rank)
        ->setFormat('json');

      return $this->handleView($view);
    }

    return $this->handleView(View::create($form, 400));
}

But form->isValid fails due to setting null values to form.

After Binding form form->getData() will display :


MyProject\DataBundle\Entity\Rank Object
(
    [city:MyProject\DataBundle\Entity\Ranking:private] => 
    [rank:MyProject\DataBundle\Entity\Ranking:private] => 
    [comment:MyProject\DataBundle\Entity\Ranking:private] => 
)   

RankType code :

class RankType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('rank');
        $builder->add('city');
        $builder->add('comment');
    }

    /**
     * {@inheritdoc}
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class'        => 'Myporject\DataBundle\Entity\rank',
            'csrf_protection'   => false,
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function getName()
    {
        return 'rank';
    }
}

Validation will throw error like city and rank should not be null

Any suggestions why $form->bind not binding values?

  • 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-14T08:19:22+00:00Added an answer on June 14, 2026 at 8:19 am

    I think, that I’ve just resolved the same problem in my app 🙂

    Look at your form: getName() method returns ‘rank’ – and this is the name of the form AND this is the namespace for this form data 🙂 Symfony2 will use it to bind.

    So, when you will send data like that:

    array('rank'=> 'somevalue', 'city' => 'comecityname', 'comment' => 'somecomment')

    it will not work, because bind method will search for array of data placed under ‘rank’ namespace and will find string ‘somevalue’. Form data will remain empty.

    Change format of data to that:

    array('rank' => array('rank'=> 'somevalue', 'city' => 'comecityname', 'comment' => 'somecomment'))
    

    and send it with REST – then it should work

    I hope this will help

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

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.