Monday 15 March 2010

php - zf2, Form collections not creating correct input name in zf2 -


I am trying to create HTML archive for color input fields .. which will be dynamically added using Javascript

My ColorFieldset is the code

  namespace dashboard \ form; Use Zend \ Form \ Fieldset; Use Zend \ InputFilter \ InputFilterProviderInterface; The Square ColorFieldset field sets the InputFilterProviderInterface {public function __construct () {origin: __ creation ('color'); $ (This' & gt; array ('name' = & gt; 'hash', 'option' => array ('label' = & gt; 'color'), 'attribute' => array ( 'Required' & gt; 'expected', 'class' = & gt; 'input-mini'))); } / ** * Return Array \ * / Public Function getInputFilterSpecification () {Return Array ('hash' = & gt; array ('required' => is true)); }}   

and added it to the form

  $ this-> Addition (array ('type' = & gt; 'jend' \ form \ element \ 'archive', 'name' = & gt; 'color', 'option' => array ('count' = & gt; 2 , 'Should_create_template' = & gt; true, 'allow_add' = & gt; true, 'target_element' = & gt; array ('type' = & gt; 'dashboard' form \ colorful set ''))));   

and in my view file .. colors.phtml

  & lt; Div id = "colors_container" class = "" & gt; & Lt ;? Php ek $ this- & gt; Form Clalling ($ form- & gt; Mill ('Color')); ? & Gt; & Lt; / Div & gt;   

This print output like

  & div; Div class = "" id = "colors_container" & gt; & Lt; Label & gt; & Lt; Span & gt; Color & lt; / Span & gt; & Lt; Input type = "text" value = "class =" input-mini "required =" required "name =" hash "& gt; & Lt; / Label & gt; & Lt; Label & gt; & Lt; Span & gt; Color & lt; / Span & gt; & Lt; Input type = "text" value = "class =" input-mini "required =" required "name =" hash "& gt; & Lt; / Label & gt; & Lt; Span data-templates = '& lt; Label & gt; & Lt; Span & gt; Color & lt; / Span & gt; & Lt; Input name = "hash" required = "required" class = "input-mini" type = "text" value = "" & gt; & Lt; / Labels & gt; '& Gt; & Lt; / Span & gt; & Lt; / Div & gt;   

It is supposed to be printed in.

  & lt; Div class = "" id = "colors_container" & gt; & Lt; Label & gt; & Lt; Span & gt; Color & lt; / Span & gt; & Lt; Input type = "text" value = "" class = "input-mini" required = "required" name = "color [0] [hash]" & gt; & Lt; / Labels & gt; & Lt; Label & gt; & Lt; Span & gt; Color & lt; / Span & gt; & Lt; Input type = "text" value = "" class = "input-mini" required = "required" name = "color [1] [hash]" & gt; & Lt; / Labels & gt; & Lt; Span data-templates = '& lt; Label & gt; & Lt; Span & gt; Color & lt; / Span & gt; & Lt; Input name = "color [__ index __] [hash]" required = "required" class = "input-mini" type = "text" value = "" & gt; & Lt; / Labels & gt; '& Gt; & Lt; / Span & gt; & Lt; / Div & gt;   

I hope the HTML input name is color [__ index __] [hash] . But this print name is & lt; Input type = "text" value = "" class = "input-mini" required = "required" name = "hash" & gt; .

In the above case. I only get a color name in $ _ POST ['hash'] .

Why not print zf2 & lt; Input type = "text" value = "" class = "input-mini" required = "required" name = "color [0] [hash]" & gt; ? Please advise what is wrong with my code.

Oh finally answered me I have to call

  $ Form- & gt; ready ();   

It works now before render anything in the scene

No comments:

Post a Comment