如何传递不带表单的POST变量?

时间:2019-03-24 22:11:10

标签: javascript php html mysql

使用PHP表来保存来自多个不同部分的注释并能够区分每个不同注释部分的最佳方法是什么?是否可以通过某种方式传递POST数据而无需表单?

我有什么办法可以区分这两种形式吗?我应该使用Javascript并通过表单ID进行区分,还是有一种更简洁的方法?

<form action="SubmitComment.php" method="post" id="comments1">
    <h3>Name:</h3><input type="text" name="name" cols="100">
    <h3>Comment:</h3><input type="text" name="comment" cols="100">
    <textarea rows=4 cols="100" placeholder="Enter text here!"></textarea>
    <?php $_POST['section'] = 1; ?>
</form>

<!-- I want to be able to distinguish between these two forms. -->

<form action="SubmitComment.php" method="post" id="comments2">
    <h3>Name:</h3><input type="text" name="name" cols="100">
    <h3>Comment:</h3><input type="text" name="comment" cols="100">
    <textarea rows=4 cols="100" placeholder="Enter text here!"></textarea>
    <?php $_POST['section'] = 2; ?>
</form>

1 个答案:

答案 0 :(得分:2)

有一种使用

区分表格的方法

<input type="submit" name="form" value="form1">

发送数据,以这种方式,您可以读取$_POST['form']值并检查其格式

如果要发送不带格式的数据,则可以将ajax与Javascript结合使用。