Ciro Vargas
Ciro Vargas

Reputation: 422

Symfony2 get item type in forms

I have a form, and need the field type in the bindrequest, the method getType dont works fine:

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

            if ($form->isValid()) {

             foreach($form as $key => $per)
                       $per->getType(); // i want the type of item [text,checkbox,etc] the method getType() dont work
 }}

Upvotes: 4

Views: 3555

Answers (1)

Mats Rietdijk
Mats Rietdijk

Reputation: 2576

Use this:

foreach($form as $key => $per) {
    $per->getConfig()->getType()->getName();
}

Upvotes: 10

Related Questions