Redirecting after form submission with user input

2020-03-08 06:13发布

I need to have a form that when filled out will create a variable and then goto a url with that variable in the url.

Something like this (but that works) :)

<form action="?????" method="?????">

Number: <input type="text" name="url1" value=""><br>

<input type="submit" name="submit" value="Goto URL">
</form>

When the submit is pressed I need it to goto http://somewhere.com?url=VALUEHERE

Any ideas?

标签: php forms submit
3条回答
甜甜的少女心
2楼-- · 2020-03-08 06:22

Use method="GET" to place the variables in the url:

<form action="http://somewhere.com/" method="GET">
    Number: <input type="text" name="url" value="" /><br />

    <input type="submit" name="submit" value="Goto URL" />
</form>

Posting this form will go to http://somewhere.com/?url=USER_INPUT_URL

查看更多
别忘想泡老子
3楼-- · 2020-03-08 06:22
<form>
Number: <input type="text" name="url1" id="url1" value=""><br>
<input type="submit" name="submit" value="Goto URL" onclick="redirect()">
</form>

<script>
function redirect()
{
  window.location='http://somewhere.com?url=' + document.getElementByID('url1').value;
}
</script>
查看更多
女痞
4楼-- · 2020-03-08 06:36

Different from 1st. No form needed, add an attribute named 'id' for the textfield,then defined a javascript function to retrieve the value of textfield,then do the jump, Hope usefully.

<form action="?????" method="?????">

Number: <input id="url1" type="text" name="url1" value=""><br>

<input type="button" name="submit" value="gotoURL()">
</form>

<script>
function gotoURL(){
window.location='http://somewhere.com?url='+document.getElementById('url1').value;
}
</script>
查看更多
登录 后发表回答