Question

I've got a problem with zend decorators and can't figure out how to place an element in form where i want to have him.

I got a form where decorators are putting my data into a table, but i want to have my submit out of the table. For now i have something like that:

for ($i = 0; $i < $numRows; $i++) {
    $select = new Zend_Form_Element_Select('article' . $i);
    $select->setAttrib('style', 'margin-top:10px;width:200px;');
    $select->addMultiOption('1', $this->translate->_('Zatwierdzony do druku'));
    $select->addMultiOption('0', $this->translate->_('Niezatwierdzony do druku'));
    $select->setValue($rows[$i]['reviewed']);
    $select->setDecorators(
      array(
        'ViewHelper',
        array(
          array('data' => 'HtmlTag'), 
          array('tag' => 'td', 'class' => 'padding5 tdcenter')
        ), 
            array(
                'AnyMarkup',
                array(
                    'markup' => $this->_getMarkupForRow($i, $rows),
                    'placement' => 'PREPEND',
                )
            ),
        array(
          array('row' => 'HtmlTag'),
          array('tag' => 'tr', 'openOnly'=>true)
        ),
      ),
      array('submit'),
      false
  );
  $this->addElement($select);
}

$submit = new Zend_Form_Element_Submit('updatetoprint');
$submit->setAttrib('id', 'updatetoprint');
$submit->setLabel('Zapisz');
$submit->setDecorators(
   array(
    'ViewHelper',
    array(
      array('data' => 'HtmlTag')
    ), 
    array(
      array('row' => 'HtmlTag'),
      array('tag' => 'div', 'closeOnly'=>true,'style' => 'float:left;')
    )
   //here i dont know how to get my submit on the bottom under the table...?
   ), 
   array('submit')
);
$this->addElement($submit);

On site that looks like this: my form

And i'd like to have my submit on the bottom under the table... Please help me :)

Était-ce utile?

La solution

I don't see where you are assigning your form to the view or if your form is a Zend_Form or not so I'm going to make some assumptions.
I'm going to assume you are using Zend_Form to build your form and I'm going to assume you are assigning your form to the view in the traditional manner inside a controller action
$this->view->form = $form;
So with that being said, in your view script you have access to each individual element simply by
<?php echo $this->form->elemenetName ?>
where elementName is the name you have given your element in your case your submit button has the name 'updatetoprint'.
With this in mind if you need to create a table or any other layout you could simply create generic elements in your form and just add them as needed to any view script. Might prevent you from performing all those gymnastics with decorators.

For example view.phtml might look like:

 <form action="<?php echo $this->form->getAction() ?>" method="<?php echo $this->form->getMethod() ?>">
    <table>
      <tr>
        <th>Dodal</th>
        <th>Tutyl</th>
        <th>Status</th>
      </tr>
    <!--you should probably put the next 5 lines into a partial and use partialLoop($data)-->
      <tr>
        <td><?php echo $this->form->dodal ?></td>
        <td><?php echo $this->form->tutyl ?></td>
        <td><?php echo $this->form->status ?></td>
      </tr>
    </table>
    <?php echo $this->form->updatetoprint ?>
    </form>

Then just style with css.

To setup the form to use the viewscript just use:

$form->setDecorators(array(
    'PrepareElements',
    array('ViewScript', array('viewScript' => 'form.phtml')),
));

where form.phtml is your viewscript name

[Edit] After further consideration I realized that diplaying form elements in this manner has one serious drawback. The form is never initialized...the form tags are never sent. This edit is to correct that issue.
Sorry it took so long

Autres conseils

I'd suggest adding all your elements apart from the submit button to a display group. You then give the display group a HtmlTag decorator (with the tag set to table), which will wrap all your elements with a table, making your HTML valid and giving you the layout you want.

I'm seeing lots of <tr> and <td> tags, but no <table> tag. What I think you are looking for is markup roughly like this:

<table>
    <tr><td>info</td><td>more info</td><td>select element</td></tr>
    <tr><td>info</td><td>more info</td><td>select element</td></tr>
    <tr><td>info</td><td>more info</td><td>select element</td></tr>
</table>
<div>
    <input type="submit">
</div>

What seems to be missing from your code are any decorators that produce the <table> and </table> tags. So, on the first iteration of the loop, use the AnyMarkup decorator to prepend a <table> and your header row. On the last iteration, add a decorator that appends the </table> tag.

Then your submit button (which is added last) should sit right underneath.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top