简体   繁体   English

php foreach提交按钮

[英]php foreach submit button

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. 我遇到的问题是我的表单提交按钮(因为它位于foreach循环中)最终会为foreach运行的每个项目最终提交。 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. 如果我将其放在循环外部,则提交没有正确的提交编号,最终将提交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 -->

} ?> }?>

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()移至循环之外,并检查$ _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! 请清理您的输入内容以及所有好东西!

从循环以及按钮中移动<form>标记,这应该对您有用

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 数组帖子的示例: http : //www.pickndrive.info/questions.php

check the form html for example 例如检查表单html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM