php Action 方法: how to redirect the user input to userinput+required extension?

标签 php html css google-web-designer

我正在使用 php 代码将我的控件重定向到一个已知页面

<form action="abc.html" autocomplete="on", method="post">
What to you want to become?:<input type="text" name="fname">
<input type="submit">

我想根据用户输入更改 abc.html 名称。如果用户输入 xyz,点击提交后,用户应该被重定向到 xyz.html。

如果不可能,除了 php 之外,还有什么好的方法可以做到这一点吗?

谢谢

最佳答案

是的,使用 vanilla JavaScript 是可能的。

  1. 给表单一个ID:

    <form id="myform" action="abc.html" autocomplete="on" method="post" onsubmit="return myfunction(this.id)">

  2. 然后在 JavaScript 中定义函数 myfunction()将用户定向到指定页面:

    <script type="text/javascript">
    function myfunction(id) {
    var fname = document.getElementByName('fname').value;
    if(fname=="xyz") {
        document.getElementById(id).action = "xyz.html";
        return true;
    }
    return true; // submit form anyways
    </script>
    

现在输入xyz在输入中,表单将转到 xyz.html

关于php Action 方法: how to redirect the user input to userinput+required extension?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46751323/

相关文章:

PHP 指针行为异常

javascript - 为什么要在点击事件期间抓取<body>?使用 .on() 而不是 .click()

html - 我的模板的包装器漂浮在我的页脚上

javascript - 拖动滚动包含 float div 的 div

html - Bootstrap 3 div 显示 block

php - 大资源吞噬者

php - 如何存储动态本地化字符串

python - 如何在基于 folium 的 map 中将动态字符串值从 Python 传递到 html?

css - 如何动态调整 div 的大小以占据可能的最大宽度?

html - 在 php 返回和 html 之间中断