1

I tried build form for a list of books. And i want make to update every quantity position in every row. I thought i can create dynamic form with one field like quantity.

$zendFormUpdate = new Zend_Form;
for ($i = 0; $i < 4; $i++){
    $quantity[$i] = $this->addElement('text','quantity'.$i,[
        'required' => false,
     ]);
}
$this->view->forms = ['formupdate' => $zendFormUpdate];

And now i would like ask you, how can i get this fields ? I am using code below but i can't get anything

<html>
    <body>
        <p>
        <form>
            <?php for ($i = 0; $i < 4; $i++){ ?>
            <?php echo $this->forms['formupdate']->quantity.$i; ?>
            <?php } ?>
        </form>
        </p>
    </body>
</html>

1 Answer 1

1

Try:

// note the s after ->form, as well
$this->forms['formupdate']->getElement( 'quantity' . $i );

But since it's a typographical error, this:

$this->forms['formupdate']->{ 'quantity' . $i };

should work as well. I forgot you could access Zend_Form elements in this manner too.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes $this->forms['formupdate']->getElement( 'quantity'.$i ) works perfect for me THANK YOU
@user4347073 You're welcome! I missed the $i at first. I've added those, so now you can see how to use the $i in the alternative syntax, as well.
yes yes it is ok now. Thx bro u saved my time i tried figure out from yesterday :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.