如何修复以下表单提交代码?

时间:2018-03-28 13:46:00

标签: javascript php jquery

网页网址:

 http://website.net/page

提交后在地址栏中输出:

http://website.net/page?paste=text

我希望结果看起来像这样:

http://website.net/page?text

没有输入的名称出现

有办法吗?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<?php
$u = $_SERVER['REQUEST_URI'];

$n = '/paste?\D(.+]?)/';

preg_match($n, $u, $n);

$url = "$n[1]";

echo $url;
?>

<form id="a">
<input type="text" id="paste" name="paste" maxlength="5" size="5" onchange="submit()">
</form>

1 个答案:

答案 0 :(得分:0)

尝试这样的事情......

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<?php
$u = $_SERVER['REQUEST_URI'];
$n = '/paste?\D(.+]?)/';
preg_match($n, $u, $n);
$url = "$n[1]";
echo $url;
// Check if is set
if (isset($_POST['paste'])) {
    // Echo input value
    echo $_POST['paste'];
}
// Change method to post
?>
<form id="a" method="POST">
    <input type="text" id="paste" name="paste" maxlength="5" size="5" onchange="submit()">
</form>