繁体   English   中英

$ _POST到另一页上的表单

[英]$_POST to a form on another page

我最初使用的是$ _GET方法:

'<a href = "editNews.php?starts='.$starts.'&ends='.$ends.'&$event='.$event.' data-role="button" data-icon="edit"></a>'

使用此方法有效,但有人告诉我使用$ _POST方法更好,更混乱,只是首选。

所以我想知道我将如何实现与上面相同的事情,但是使用$ _POST方法。

您可以使用方法post提交表单,也可以使用ajax请求。 在jQuery中,这看起来像:

$("#myLinkId#").on('click',function() {
    $.ajax({url:'phpFile.php',type:'post',data:{...you data here...}});
});

您需要将其转换为表单,或者使用jQuery在点击时触发Ajax调用。 这是一个表单示例:

<form action="editNews.php" method="post">
    <input type="hidden" name="starts" value="<php echo $starts?>">
    <input type="hidden" name="end" value="<php echo $end?>">
    <input type="hidden" name="event" value="<php echo $event?>">
    <input type="submit" name="submit" value="Your Link" data-icon="edit">
</form>

要将数据通过PHP发送到另一个页面/表单,您可以执行以下操作:

原始形式:

<form method='post' action='new-page.php'>
  inputs here, etc.
  submit button here
</form>

因此,这将在单击提交后将您发送到new-page.php,并将所有表单数据保存在PHP变量$_POST ,该变量是一个数组。

您可以通过使用输入名称引用数组来访问数据,例如,假设您拥有:

<input type='text' name='NAME' />

您可以使用$_POST['NAME']new-page.php上引用此数据。

我希望这可以帮助你!

暂无
暂无

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

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