Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从用户输入重定向到url_Php_Jquery_Wordpress_Redirect - Fatal编程技术网

Php 从用户输入重定向到url

Php 从用户输入重定向到url,php,jquery,wordpress,redirect,Php,Jquery,Wordpress,Redirect,我试图在wordpress中执行一项非常简单的任务。用户在文本字段中输入一个数字,然后单击重定向到url/输入 用户输入:123456 用户重定向到http://example.com/123456(不是/?url=123456等) 我在这里讨论了几个答案,但这似乎不像听起来那么简单 谢谢 好吧,我不是一个编码员,因此我不是一个这样思考的人:)但这里是这样的: 在woocommerce中,我有成千上万的优惠券代码。我想提供100%折扣的兑换代码,免费数字下载。我正在使用url优惠券插件,它能够在

我试图在wordpress中执行一项非常简单的任务。用户在文本字段中输入一个数字,然后单击重定向到url/输入

用户输入:
123456

用户重定向到
http://example.com/123456
(不是
/?url=123456
等)

我在这里讨论了几个答案,但这似乎不像听起来那么简单

谢谢

好吧,我不是一个编码员,因此我不是一个这样思考的人:)但这里是这样的:

在woocommerce中,我有成千上万的优惠券代码。我想提供100%折扣的兑换代码,免费数字下载。我正在使用url优惠券插件,它能够在进入某个页面时添加产品和优惠券,然后重定向到另一个页面,比如说购买页面

转到将添加产品和优惠券,然后转到购买页面。但这只是一张优惠券。如何为每个优惠券代码实现这一点

所以我想为每个优惠券创建重定向规则,并将它们重定向到一个页面,该页面将添加产品和优惠券,然后转到购买页面。 如果优惠券是正确的,它将被添加,一切都很酷。如果优惠券代码无效,它将没有重定向规则,并将转到404页或其他专用页。 现在我需要让用户输入优惠券代码并重定向

enter code here
<form id="form">
<input type="text" id="my-code">
<input type="submit" value="Submit">
</form>
document.getElementById("form").onsubmit = function () {

var url = document.getElementById("my-code").value;

window.location.assign('/' + url);
}
在此处输入代码
document.getElementById(“表单”).onsubmit=function(){
var url=document.getElementById(“我的代码”).value;
window.location.assign('/'+url);
}

我刚刚看到您使用jQuery编辑了第一条消息:

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

<form id="soTest" action="registerCoupon">
    <input type="text" id="coupon" name="coupon" value="Coup123456">
    <input type="submit" value="Submit">
</form>

<script>
$('#soTest').submit(function(ev) {
    var coupon = document.getElementById("coupon").value;
    ev.preventDefault();
    window.location.assign('/' + coupon);
});
</script>

$('soTest')。提交(函数(ev){
var优惠券=document.getElementById(“优惠券”).value;
ev.preventDefault();
window.location.assign(“/”+优惠券);
});
使用PHP,您可以尝试:

<?php
    $link = "testLink";
    header("Location: http://aaa.fr/".$link);
?>


window.location.assign('/'+userInputValueHere)你试过什么?你的代码在哪里?你为什么想要这样的东西。闻起来像糟糕的应用程序设计。请描述您的意图,我相信我们将帮助您找到最佳解决方案。请看上面…@JanRydrych你a:)谢谢!url转到/RegisterCompon?优惠券=123456我正在尝试在跟踪后只使用用户输入,但这可能是不可能的。实际上,这是完美的,可以添加重定向规则。谢谢