Display only the <form> tag

Is there a way that I can display ONLY the start tag of <form>a Zend_Form object?

print $this->registerForm->renderForm();

displays <form></form>and I only need<form>

Edit:

After solving Asleys, I wrote this for the My_Form class

public function renderFormOpen() {
    return str_replace('</form>', '', $this->renderForm());
}

public function renderFormClose() {
    return '</form>';
}

They are still looking for ZF ways to make thin, although I don’t think they are - after going through the code in the ZF library.

+3
source share
3 answers

, , . , .
"hardcode" - , .

<!--in your view-template -->
<form action="<?php echo $this->form->getAction() ?>"
      enctype="<?php echo $this->form->getEnctype() ?>"
      method="<?php echo $this->form->getMethod() ?>"
      id="<?php echo $this->form->getId() ?>"
      class="<?php echo $this->form->getAttrib('class') ?>" >

    <!--in case your products are represented as elements -->
    <?php foreach ($this->form->getElements() as $element): ?>
       <?php echo $element ?>
    <?php endforeach; ?>

    <!--in case your products are represented as displayGroups -->
    <?php foreach ($this->form->getDisplayGroups() as $displayGroup): ?>
       <?php echo $displayGroup ?>
    <?php endforeach; ?>

    <!--in case your products are represented as subforms -->
    <?php foreach ($this->form->getSubforms() as $subform): ?>
       <?php echo $subform ?>
    <?php endforeach; ?>

    <!--in case your products are rendered by a view helper -->
    <?php foreach ($this->products as $product): ?>
       <?php echo $this->renderProduct($product) ?>
    <?php endforeach; ?>
</form>

// Get your products form
$form = new Form_Products();
// Add custom prefix path
$form->addPrefixPath('Foobar_Form_Decorator', 'Foobar/Form/Decorator', 'decorator');
// Set OnlyOpenTagForm-ViewHelper for FormDecorator
$form->getDecorator('Form')->setHelper('OnlyOpenTagForm');

// copy Zend/View/Helper/Form to Foobar/Form/Decorato/OnlyOpenTagForm.php
// In OnlyOpenTagForm.php
//   replace Zend_View_Helper_Form with Foobar_View_Helper_OnlyOpenTagForm
//   replace method "form" with onlyOpenTagForm"
//   replace
if (false !== $content) {
    $xhtml .= $content
           .  '</form>';
}
//   with:        
if (false !== $content) {
    $xhtml .= $content;
}

! - Java- ;)

+5

, false :

<?php echo $this->form->renderForm(false) ?>

- :

<form id="post" enctype="multipart/form-data" method="post" action="/post">

, , :

<?php echo $this->form->renderForm('Some Text') ?>

- :

<form id="post" enctype="multipart/form-data" method="post" action="/simchas/post">Some Text</form>

, ...

+4

- :

echo $this->form->getDecorator('Form')->setElement($this->form)->render(false);
0

Source: https://habr.com/ru/post/1754698/


All Articles