php - Symfony form validation basic form -


i have user entity class this: namespace appbundle\entity;

use doctrine\orm\mapping orm; use doctrine\orm\mapping\onetoone; use doctrine\orm\mapping\joincolumn; use symfony\component\validator\constraints assert;   /** * @orm\entity * @orm\table(name="clients") */ class clients {     /**     * @orm\column(type="integer")     * @orm\id     * @orm\generatedvalue(strategy="auto")     */    private $id;     /**     * @orm\column(type="string", length=255, nullable=false)     * @assert\notblank(     *      groups={"registration"},      *      message = "il campo nome non può essere vuoto."     * )     */     private $name; 

then, have clientstype this:

namespace appbundle\form;  use symfony\component\optionsresolver\optionsresolver; use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface;  class clientstype extends abstracttype {      public function buildform(formbuilderinterface $builder, array $options) {         $builder->add('name');     }      public function getname() {         return "clients";     }      public function configureoptions(optionsresolver $resolver)     {         $resolver->setdefaults(array(         'data_class' => 'appbundle\entity\clients',         'validation_groups' => array('registration'),         ));     }  } 

and controller:

    if ($request->ismethod('post')) {          $client = new clients();          $form = $this->createform(clientstype::class, $client);          $form->handlerequest($request);          $data = $form->getdata();         print_r($data);          if ($form->isvalid()) {             echo "yes";         }             else{             echo "no";         }          die();     } 

i view there simple html form.

<input type="text" class="form-control" value="{{last_name}}" id="name" name="name" placeholder="nome"> 

the problem if send or not "name" receive "no"...

thank you...fabio.

i think form not validated correctly, because input name in template wrong, form not filled post data. try change name="name" name="clients[name]" or transmit form template $form->createview() , output element {{ form_widget(form.name) }}


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -