php foreach提交按钮
我遇到的问题是我的表单提交按钮,因为它位于 foreach 循环内,最终会提交 foreach 运行的每个项目。如果我将它放在循环的外部,则提交没有要提交的正确编号,它最终会提交 foreach 中的最后一个值。有人有解决方案吗?
<div data-role='collapsible' data-collapsed='true' data-icon='arrow-l'>
<h3><?=$ticket['ticket_no']?> - <?=$ticket['title']?></h3>
<div class="ui-body ui-body-a">
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="c">
<li data-role="list-divider"><h1></h1></li>
<li><h3>Description</h3><br><br><?=$ticket['description'] ?></li>
<input type=hidden name=ticket_number value=<?= $ticket['ticket_no']; ?>>
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<div data-role="fieldcontain">
<label for="status" class="select">Change Status:</label>
<select name="status" id="<?=$ticket['ticket_no']?>">
<option value="Open">Status</option>
<option value="Tracker">Tracker</option>
<option value="Abandon">Abandon</option>
<option value="Communicate">Communicate</option>
<option value="Closed">Closed</option>
</select>
</div>
<input type="submit" data-theme="a" name="submit" value="Submit"></input>
</fieldset>
</form>
</div><!-- /themed container -->
</div> <!-- End inner collapsible set -->
} ?>
The issue I am having is that my form submit button, because it is within the foreach loop, ends up submitting for every single item that the foreach runs through. If I put it on the outside of the loop the submit does not have the correct number to submit, it ends up submitting the last value in the foreach. Does anyone have a solution for this?
<div data-role='collapsible' data-collapsed='true' data-icon='arrow-l'>
<h3><?=$ticket['ticket_no']?> - <?=$ticket['title']?></h3>
<div class="ui-body ui-body-a">
<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="c">
<li data-role="list-divider"><h1></h1></li>
<li><h3>Description</h3><br><br><?=$ticket['description'] ?></li>
<input type=hidden name=ticket_number value=<?= $ticket['ticket_no']; ?>>
<form action="<?=$_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<div data-role="fieldcontain">
<label for="status" class="select">Change Status:</label>
<select name="status" id="<?=$ticket['ticket_no']?>">
<option value="Open">Status</option>
<option value="Tracker">Tracker</option>
<option value="Abandon">Abandon</option>
<option value="Communicate">Communicate</option>
<option value="Closed">Closed</option>
</select>
</div>
<input type="submit" data-theme="a" name="submit" value="Submit"></input>
</fieldset>
</form>
</div><!-- /themed container -->
</div> <!-- End inner collapsible set -->
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在每种形式中,输入如下内容:
然后将 if() 移至循环外部,并检查 $_POST['ticket_number']
这是通过尽可能少的更改完成的。请清理您的输入以及所有这些好东西!
In each form, put something like:
and then move your if() to outside of the loop, and check for $_POST['ticket_number']
This was done with the least amount of change possible. Please sanitize your input, and all that good stuff!
将
move the
<form>
tags from the loop as well as the button, that should work for you您当前正在覆盖字段的问题,因为它们具有相同的名称。
[]就是你所需要的!
现在,在您发布后,您将获得状态数组中的所有门票。当您收到状态循环时,它会获取每个值。
数组帖子示例: http://www.pickndrive.info/questions.php
检查表单例如,html
the problem you are currently overwriting your fields as they have same name.
[] is what you need !.
now after you post u will get all tickets in status array. when u receive status loop it to get each value.
example of array post : http://www.pickndrive.info/questions.php
check the form html for example