dongxiangxie8181 2013-06-20 12:40
浏览 30
已采纳

PHP具有单个动作的多个表单

I've multiple forms with a single action, a single php page that gets called by all the forms.

How can I differentiate which form was sent to the php page?

  • 写回答

5条回答 默认 最新

  • dongtuoji5396 2013-06-20 12:41
    关注

    Using a different unique input type="hidden" for each form.

    HTML:

    <input type="hidden" name="form_id" value="1">
    <input type="hidden" name="form_id" value="2">
    

    PHP:

    $myform = $_POST["form_id"];
    

    You can also use the submit button but note that the "value" parameter is what gets displayed to the user so you won't be able to modify it (assuming you want the same text to be displayed on every button).

    <input type="submit" name="action" value="the user saw this">
    

    PHP:

    $_POST["action"] // -> "the user saw this";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?