zend framework2 - ZF2 form to change multiple parameters -
For example, using the ZF2 Album Module, I would like to be placed on the index view, which can be enabled.
year column, and we wanted to see the index to have a form with two related elements. The form is a simple form, so we do not want a submit button; Instead, we want the user to trigger the form selection form. Based on the input from the controller router, sets $ style-filter and $ year , and those values 1) filter the data sent to the view and 2) set Do a ???? Selected Option of the selected element in the form. How can I do this? I have a lot of questions on which I can not find information:
-
How can I trigger the form action to select elements? This selection in HTML is done by adding tag to onchange = 'this.form.submit ()' . How can I do this in ZF2? -
How can I indicate what are the options in the selection element? (Current default) option? This is done in HTML by adding 'selected' to an option tag. How can I do this in ZF2? -
How do I write a form action script?
Here? What have I done so far:
// In controller: use Zend \ Form \ Element; Use Zend \ Form \ Form; // ... // $ style-filter = $ this- & gt; GetEvent () - & gt; getRouteMatch () - & gt; getParam ('style'); $ year-filter = $ this- & gt; GetEvent () - & gt; getRouteMatch () - & gt; getParam ('year'); // ... // $ genre = new element \ select ('style'); $ genre- & gt; SetValueOptions (array ('all' = & gt; 'all', 'jazz' = & gt; 'jazz', 'punk' = & gt; 'punk', 'emo' => 'emo', / / ... //)); $ Year = new element \ select ('year'); $ Year- & gt; SetValueOptions (array ('all' = & gt; 'all', '2001' => 2001 ', 2002' = '2002', '2003' => 2003),) ; $ form = new form ('event-filter'); $ Form & gt; (Style $); $ Form & gt; ($ Years) add; In the View script, and
//: $ echo-> () -> OpenTag ($ form); Echo "style:" $ this-> formSelect (style $); Echo "year:" $ this- & gt; formSelect ($ year); Echo $ the-> Form () - & gt; CloseTag (); I think the form action has written something like this: in the controller
// $ genre-select = $ this-> getRequest () - & gt; getPost ('style', 'all'); $ year-selection = $ this- & gt; getRequest () - & gt; getPost ('year', 'all'); $ $ --- $ (- 'albums', array ('action' => 'index', 'style' => style-selection, 'year' = & gt; $ year-selection);
1. How do I select the elements In the HTML it is triggered the form addition? In HTML, it is done by adding onchange = 'this.form.submit ()' to the tag. How do I do it in ZF2? You define While specifying individual form elements, you can specify attributes:
$ style = new element \ Select (style '); $ genre- & gt; setAttributes (array (' onchange '= & gt;' this.form.submit (); ')); However HTML Add it to your JS file: / p>
if (document.getElementById ('event-filter')) {$ ('# event -filter select '.) Change (function (e) {$ (' # event-filter ') .submit ();})}} 2. How do I tell which option is the element one? Is selected (current default) option? This is done in HTML by adding 'Selected' to an option tag. How can I do this in ZF2? $ form = new form ('event-filter'); $ Form- & gt; Setdata (array ('style' = & gt; 'jazz', 'year' => gt; 2002)); 3. How do I write a form action script? It really depends on how you are already loading data, but if you have a specific problem, then maybe we can help.
Comments
Post a Comment