php - Symfony2 form doesn't show any errors yet it doesn't display -
good day, have form in sf2 it's bine linked entity , i'm having trouble solving issues it. start form get's displayed write amount of text get's submit if run print_r($_post) in method controller shows me data i've submited if run inside isvalid() i'm not getting , i'm not getting errors , leaves me no idea i'm doing wrong , how fix it.
controller:
/** * @route("/papetarie/cautare", name="papetarie_search_form") * @template("catalogbundle:default:search_form.html.twig") */ public function showsearchformaction(request $request) { $form = $this->createformbuilder() ->add('keyword', 'text', array( 'label' => 'cautare produs', 'label_attr' => array('class' => 'sr-only'), 'attr' => array( 'placeholder' => 'cautare produs', 'pattern' => '.{2,}', //minlength 'class' => 'col-md-10' ), 'constraints' => array( new notblank(array('message' => 'campul nu poate sa fie gol')), new length(array('min' => 2)) ), )) ->add('submit', 'submit', array('attr' => array('class' => 'save btn-primary'))) ->getform(); $form->handlerequest($request); if($form->isvalid()) { $data = $form->get('keyword')->getdata(); print_r($data); } return array( 'search_form' => $form->createview() ); }
search_form.html.twig
{% label, flashes in app.session.flashbag.all %} {% flash in flashes %} <div class="alert alert-{{ label }}"> {{ flash }} </div> {% endfor %} {% endfor %} {{form_start(search_form, {'action': path('papetarie_search_form'), 'method' : 'post', 'attr': {'id': 'papetarie_search_form', 'class': 'form-inline'} })}} <div class="input-group col-md-10"> {{ form_label(search_form.keyword) }} {{ form_errors(search_form.keyword) }} {{ form_widget(search_form.keyword) }} </div> {{ form_widget(search_form._token) }} {{form_end(search_form)}}
the way i'm displaying form
<div class="col-md-12"> {{ render(controller('catalogbundle:default:showsearchform')) }} </div>
the output get_class_methods()
array(42) { [0]=> string(11) "__construct" [1]=> string(7) "__clone" [2]=> string(9) "getconfig" [3]=> string(7) "getname" [4]=> string(15) "getpropertypath" [5]=> string(10) "isrequired" [6]=> string(10) "isdisabled" [7]=> string(9) "setparent" [8]=> string(9) "getparent" [9]=> string(7) "getroot" [10]=> string(6) "isroot" [11]=> string(7) "setdata" [12]=> string(7) "getdata" [13]=> string(11) "getnormdata" [14]=> string(11) "getviewdata" [15]=> string(12) "getextradata" [16]=> string(10) "initialize" [17]=> string(13) "handlerequest" [18]=> string(6) "submit" [19]=> string(4) "bind" [20]=> string(8) "adderror" [21]=> string(11) "issubmitted" [22]=> string(7) "isbound" [23]=> string(14) "issynchronized" [24]=> string(24) "gettransformationfailure" [25]=> string(7) "isempty" [26]=> string(7) "isvalid" [27]=> string(16) "getclickedbutton" [28]=> string(9) "geterrors" [29]=> string(17) "geterrorsasstring" [30]=> string(3) "all" [31]=> string(3) "add" [32]=> string(6) "remove" [33]=> string(3) "has" [34]=> string(3) "get" [35]=> string(12) "offsetexists" [36]=> string(9) "offsetget" [37]=> string(9) "offsetset" [38]=> string(11) "offsetunset" [39]=> string(11) "getiterator" [40]=> string(5) "count" [41]=> string(10) "createview" }
the way dump errors see error
if(!$form->isvalid()) { echo "<pre>"; //var_dump($form->geterrors()); var_dump(get_class_methods($form)); }
if do
var_dump($form->geterrorsasstring());
i
string(0) ""
while still looking solution found interesting. if change route /search example instead of /office/search , submit form form get's data , works fine.
action return statement have like
return $this->render('catalogbundle:default:search_form.html.twig', array('search_form' => $form->createview()));
add exit;
after print_r
.
Comments
Post a Comment