April 7, 2012
multiple forms in same page Jquery Ajax submit
Question by KJA
I am iterating a form in phtml page
how can i Submit or validate the form when i click in the button.
because when i am iterating the form , the id is the same for all form
i am using Zend Framework , i initiate the Form in my view like this to get different ids for each form
<?php
$commentForm = new Application_Form_Comment**($answerId)**;
echo $commentForm?>
and i sent the $answer[‘answer_id’] to put it in the form id to be like this
<form id="comment_form64623" method="post" action="">
is that the best way ? or there is a way in Jquery to handle that?
Answer by Starx
I will say, no its not the good way, attaching ID, like that. Configure zend’s form to take the id as a hidden paramter, which at last renders as
<form id="comment_form" method="post" action="">
<input type="hidden" name="answer_id" id="answer_id" value="64623" />
Next configure jQuery to change the position of the form to different places and update, like
$("form").appendTo($("#newDiv")); //Place the for somewhere else
$("#answer_id").val(newval); //Set a new id for the form