简体   繁体   English

PHP - 如何在不提交表单的情况下获取html输入的内容?

[英]PHP - How do you get the content of an html input without submitting the form?

In my program, the href redirects to another page with the $id, and I am able to edit the row with that id from that page (signoutteacher.php). 在我的程序中,href重定向到另一个带有$ id的页面,我可以编辑该页面中带有该id的行(signoutteacher.php)。 No I also want to be able to transfer the location from the input box, but I need a button to do so. 不,我也希望能够从输入框传输位置,但我需要一个按钮来执行此操作。 Does anyone have an idea of how I could do both using only one button? 有没有人知道如何只使用一个按钮来做两件事?

while ($row = mysqli_fetch_array($result)){
  $id = $row['id'];
  if ($row['status']== "In"){echo "<tr class='w3-hover-green w3-large'>";
    echo "<td width='10%'>".$row['name']."</td>";
    echo "<td width='10%'>".$row['surname']."</td>";
    echo "<td width='5%'>".$row['status']."</td>";
    echo "<td width='20%'><form action='Teacher.php' method='post'><input type='text' name='location'></form></td>";
    $location=$_POST['location'];
    echo "<td width='10%'>"."
    <a href='signoutteacher.php?myId=".$id."&myLocation=".$location."' class = 'w3-btn w3-input w3-green w3-round-jumbo'>Sign Out</a>
    </td>";
    echo "</tr>";

The table heading have already been printed out, and everything else works fine when not considering the location. 表格标题已经打印出来,其他一切工作正常,不考虑位置。 The error message says that the index 'location' is not defined. 错误消息表明未定义索引“位置”。 I know that I need to submit the input, but how? 我知道我需要提交输入,但是如何?

Instead of including the $id in the url, I created a form where the $id is a hidden input and sent that to the form along with the location. 我没有在网址中包含$ id,而是创建了一个表单,其中$ id是一个隐藏的输入,并将其与位置一起发送到表单。 Now everything works fine. 现在一切正常。

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

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