user2269869
user2269869

Reputation: 191

add a text area to form symfony2

I have a form related to an entity. I want to add a text area number to the form and get the value entred, knowing that I don't have an attribute in the entity with this value so neither getNumber() nor setNumber. I also want it to be submitted with the form.

How can I achieve that?

I found out this link and tried

->add('From', 'text', array(
                "property_path" => false,
            ));

But what I want to know how to get this value now? can it be submitted with the form?

Upvotes: 1

Views: 307

Answers (1)

Hugo Dozois
Hugo Dozois

Reputation: 8420

The value will be submitted with the form. Therefore you can retrieve it directly in the "Request" object.

In your case you would do

$this->get('request')->request->get('From');

See the cookbook about form without classes for more information.


You can also retrieve the request object by having a parameter of the type Request in your function :

use Symfony\Component\HttpFoundation\Request;

public function myFunction(Request $request /*, ... */){
    //...

    $from = $request->get('From');

    //...
}

Upvotes: 1

Related Questions