如何调用新页面并添加表单变量的值

时间:2021-11-06 21:12:29

I would like to link to a new page in the format:

我想链接到以下格式的新页面:

/topic/create&qty=4

Right now I have the value (which is the number 4) stored in an field in a form. I tried to put everything in the form with a post but then realized this isn't what I want to do. I just need clicking on a button to go to link to a new page and send the input field value. The reason I want just a link is that later on I will have posts from that form and they will be handled completely differently.

现在我有一个存储在表单字段中的值(即数字4)。我尝试将所有内容放在表格中,然后意识到这不是我想要做的。我只需要点击一个按钮就可以链接到新页面并发送输入字段值。我想要一个链接的原因是,稍后我将从该表单中获得帖子,它们将以完全不同的方式处理。

Is this possible? All I know is that

这可能吗?我只知道的是

<form action="/adminTopics" method="post">

isn't what I need.

不是我需要的。

2 个解决方案

#1


0  

you can not use POST to send data via url, but you can use GET like this: /topic/create?qty=4

你不能使用POST通过url发送数据,但你可以像这样使用GET:/ topic / create?qty = 4

EDIT: Clarification

编辑:澄清

Writing red in the text field and pressing submit on this form...

在文本字段中写入红色并按此表单上的提交...

<form action="/handler.php" method="GET">
    <input type="text" name="color" />
    <input type="submit" />
</form>

will produce identical results on the server side to clicking this link

将在服务器端生成相同的结果单击此链接

<a href='/handler.php?color=red'>rum</a>

#2


0  

If the url is /topic/create?qty=4

如果网址是/ topic / create?qty = 4

and it has to be posted, then you can use

它必须发布,然后你可以使用

<form action="/topic/create" method="post">
<input type="hidden" name="qty" value="4" />
</form>

<a href="#" onclick="document.forms[0].submit(); return false">Send</a>

or

要么

<script>
window.onload=function() {
  document.forms[0].submit();
}
</script>

If you do NOT need POST, then just call the URL which is the same as a GET

如果您不需要POST,那么只需调用与GET相同的URL即可

<input id="qty" type="hidden" name="qty" value="4" />

<a href="/topic/create"
 onclick="location=this.href+'?qty='+document.getElementById('qty').value; 
 return false">Go</a>

#1


0  

you can not use POST to send data via url, but you can use GET like this: /topic/create?qty=4

你不能使用POST通过url发送数据,但你可以像这样使用GET:/ topic / create?qty = 4

EDIT: Clarification

编辑:澄清

Writing red in the text field and pressing submit on this form...

在文本字段中写入红色并按此表单上的提交...

<form action="/handler.php" method="GET">
    <input type="text" name="color" />
    <input type="submit" />
</form>

will produce identical results on the server side to clicking this link

将在服务器端生成相同的结果单击此链接

<a href='/handler.php?color=red'>rum</a>

#2


0  

If the url is /topic/create?qty=4

如果网址是/ topic / create?qty = 4

and it has to be posted, then you can use

它必须发布,然后你可以使用

<form action="/topic/create" method="post">
<input type="hidden" name="qty" value="4" />
</form>

<a href="#" onclick="document.forms[0].submit(); return false">Send</a>

or

要么

<script>
window.onload=function() {
  document.forms[0].submit();
}
</script>

If you do NOT need POST, then just call the URL which is the same as a GET

如果您不需要POST,那么只需调用与GET相同的URL即可

<input id="qty" type="hidden" name="qty" value="4" />

<a href="/topic/create"
 onclick="location=this.href+'?qty='+document.getElementById('qty').value; 
 return false">Go</a>