dongshao4207 2019-01-06 20:12
浏览 100
已采纳

如何从PHP生成的表单中获取值?

I dont know where or how to use $_POST to get the values of the forms.

This is the whole code, I uploaded it on GitHub if you want to see the whole thing

This is the file I am trying to get the values out of.

new.php

<?php
if (!empty($_POST) and isset($_POST['actiune']))
{
$actiune = isset($_POST['actiune']) ? $_POST['actiune'] : NULL;
switch($actiune){
//CASE 1
case 'addElev': echo '<div class=dbFormText>Adauga elev</div><div 
class="databaseform"><form action="" method="post">
<input type="text" name="numeElev" placeholder="Nume elev"/>
<input type="text" name="orasElev" placeholder="Localitate"/>
<select name="sexElev">
<option value="Baiat">Baiat</option>
<option value="Fata">Fata</option></select>
<input type="text" name="tlfElev" placeholder="Nr. de telefon"/>
<input type="text" name="birthdayElev" placeholder="Nastere(DD-MM-YYYY)"/>
<input type="submit" value="Submit">
</form></div>';
break;
}
}
?>

This is the page of the first dropdown, which gives me the value of the switch

adminpanel.html

<div class="dropdowns">
<form action="" method="post">
<select name="actiune" onchange="this.form.submit()">
<option>Selecteaza actiunea</option>
<option value="addElev">Adauga elev</option>
<option value="addNota">Adauga nota</option>
<option value="addAbsenta">Adauga absenta</option>
<option value="addTeza">Adauga teza</option>
<option value="deleteElev">Sterge elev</option>
<option value="deleteNota">Sterge nota</option>
<option value="deleteAbsenta">Sterge absenta</option>
<option value="deleteTeza">Sterge teza</option>
<option value="modifyElev">Modifica elev</option>
<option value="modifyTeza">Modifica teza</option>
<option value="modifyPurtare">Modifica nota purtare</option>
</select>
<?php include('new.php') ?>
</div>
  • 写回答

2条回答 默认 最新

  • dongteng0748 2019-01-06 20:28
    关注

    When you submit a form that has a method of post, e.g.

    <form method="post">
    

    (note: action="" is redundant and can be left out)

    the target page (in this case, itself) will be provided with the $_POST array.

    You can dump the entire array to look at the values by using:

    if (!empty($_POST) and isset($_POST['actiune']))
    {
    var_dump($_POST);
    }
    

    This array should contain all the values from within the <form> tag, provided a name has been set (which will be used as the 'key' in the array).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记