I have some dynamically added text boxes along with some static ones. The problem I’m having is when I remove an item from one of the dynamic forms, unless I have it wrapped with form tags, it will only remove the last item from the list. However, when I wrap it in form tags, then the static text boxes won’t post. Basically I’m just wondering how to properly use tags if I want to submit textboxes.
For example,
<form method="post">
<textbox 1>
<textbox 2>
<textbox 3>
<?
$tasks->task_form();
?>
<another textbox> //these text boxes don't POST when the dynamic forms have tags wrapped around them
<another textbox>
<?
$users->dynamic_form_2();
?>
</form>
For example, here’s the task_form
function task_form(){
//textbox and submit to add tasks here (omitted to keep shorter)
foreach (array_combine($task, $task_num) as $task => $task_num){
?>
<form method="post">
<tr><td><? echo $task; ?></td><td><? echo $task_num; ?></td>
<td><input type="submit" name="remove_task" value="Remove"/></td>
<td><input type="hidden" name="task_name" value="<? echo $task; ?>"/>
<td><input type="hidden" name="task_num" value="<? echo $task_num; ?>"/></td></tr>
</form>
<?
}
}
If I don’t place the form tags around the dynamic forms, then the last item from that form is removed regardless of which one I try to remove. However, with the form tags, then the values from some of the text boxes don’t POST at all.
This is probably not the cleanest solution, but you could use a toolkit like jQuery and on click of one of your submit button, simply send
ajaxqueries for each forms in parallel, and when everything is done, redirect to another page.I would still strongly advise that you review your forms, it should probably be a single form!