php foreach提交按钮

发布于 2024-12-08 12:13:56 字数 1854 浏览 1 评论 0原文

我遇到的问题是我的表单提交按钮,因为它位于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

血之狂魔 2024-12-15 12:13:56

在每种形式中,输入如下内容:

<input type=hidden name=ticket_number value=<?= $ticket['ticket_no'];  ?>>

然后将 if() 移至循环外部,并检查 $_POST['ticket_number']

if(isset($_POST['submit']) && isset($_POST['ticket_number'])) {
 $tickNum = $_POST['ticket_number'];
 updateTT($tickNum);                            
} 

这是通过尽可能少的更改完成的。请清理您的输入以及所有这些好东西!

In each form, put something like:

<input type=hidden name=ticket_number value=<?= $ticket['ticket_no'];  ?>>

and then move your if() to outside of the loop, and check for $_POST['ticket_number']

if(isset($_POST['submit']) && isset($_POST['ticket_number'])) {
 $tickNum = $_POST['ticket_number'];
 updateTT($tickNum);                            
} 

This was done with the least amount of change possible. Please sanitize your input, and all that good stuff!

凡间太子 2024-12-15 12:13:56

标签从循环和按钮中移出,这应该适合您

move the <form> tags from the loop as well as the button, that should work for you

手长情犹 2024-12-15 12:13:56

您当前正在覆盖字段的问题,因为它们具有相同的名称。

[]就是你所需要的!

<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>

现在,在您发布后,您将获得状态数组中的所有门票。当您收到状态循环时,它会获取每个值。

数组帖子示例: http://www.pickndrive.info/questions.php

检查表单例如,html

the problem you are currently overwriting your fields as they have same name.

[] is what you need !.

<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>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文