【问题标题】:php passing data formphp传递数据表单
【发布时间】:2022-01-19 11:12:19
【问题描述】:

我使用 GET 方法将数据从 index.php 传递到 profile.php

index.php 代码是

<html>
<body>

<form action="profile.php" method="GET">
username: <input type="text" username="user"><br>
password: <input type="password" name="pass"><br>
<input type="submit">
</form>

<button type="button" onclick="alert('task success')"/>click me"</button>

</body>
</html>

profile.php 代码是

<?php
    echo " username: "$_GET ['username']."; password "$_GET['pass'];
?>

输出是

它成功传递了表单的输入,但我需要它出现在 profile.php 文件中

如何使输出出现在 profile.php 页面中?

请帮忙

【问题讨论】:

  • 用户名的input标签应该是&lt;input type="text" name="username"&gt;
  • 在您的 html 代码中删除click me 之后的" 并删除click me 之前的/(在&lt;button&gt; 标记的末尾)。在您的 profile.php 中,将当前句子更改为 echo " username: ".$_GET['username']." password: ".$_GET['pass']; 并在另一条评论中进行 @kenny 修复。错别字太多。使用更好的代码编辑器来帮助您修复它们,例如 Virtual Studio CodeSublime

标签: php forms apache


【解决方案1】:

问题是页面被重定向。您需要向要执行的操作发送 AJAX 请求。使用 jQuery,您可以阻止 form 像这样提交:

$('form').submit(function (evt) {
   evt.preventDefault(); //prevents the default action

}

您需要collect the parameters, send them via AJAX and handle the response

【讨论】:

    猜你喜欢
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-20
    • 2014-05-12
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多