我想创建一个带有文本框的网站,如果用户输入“ hello”并单击提交,我想显示example.com/test.php?link=hello 我怎样才能做到这一点? php已经写好了,我只需要用html或php做一些事情就可以显示example.com/test.php?link=whatUserEnters
谢谢!
答案 0 :(得分:0)
表单应具有定义的方法“ get”。然后在test.php页面上,您
<form method="get" action="test.php">
...
<input type="text" name="link"/>
</form>
并在test.php上
<? echo $_GET['link']; ?>
或
<?= $_GET['link']?>
使用POST解决方案进行编辑:
<form method="post" action="test.php">
...
<input type="text" name="link"/>
</form>
并在test.php上
<? echo $_POST['link']; ?>
答案 1 :(得分:0)
<!DOCTYPE html>
<html>
<body>
<!--just create a text box, give an id to it.-->
<input type="text" id="text_to_display" />
<input type="button" value="Submit" onClick="concat();" />
<!--Create a label or div assign a separate id to it too.-->
<p id="concatenated_text"></p>
<script>
//Create a function in javascript.
function concat() {
//Get the value in function using that id.
var text = document.getElementById("text_to_display").value;
//Concatenate the value with the string and put it in div using id.
var final_text = "example.com/test.php?link="+text;
// you can use location.href to use it for link purpose
location.href = final_text;
}
</script>
</body>
</html>