简体   繁体   中英

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?

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');

    //...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM