表单与多个提交按钮查询外部网站

Form with multiple submit buttons that queries external website

本文关键字:查询 外部 网站 按钮 提交 表单      更新时间:2023-09-26

嗨,我需要编写一个表单,查询外部网站与三个提交按钮的代码。每个提交按钮将发送一些共同的输入字段和一些相关的具体到个别机构。我相信我将需要使用JavaScript,但我不确定我能做些什么。下面是表单的结构:

<form action="external website" method="post">
{{ form_with common input selectors }}
<!-- if submit Option one is used -->
<input type="text" name="fixed" value="option one">
<!-- if submit Option two is used -->
<input type="text" name="fixed" value="option two">
<!-- if submit Option three is used -->
<input type="text" name="fixed" value="option three">
<input type="submit" name="Option one" value="option one" />
<input type="submit" name="Option two" value="option two" />
<input type="submit" name="Option three" value="option three" />
</form>

任何来自专家的帮助将不胜感激!

那些

如果我正确理解你的问题,这将是你的答案。简单地发送三个值中的一个作为表单的一部分似乎是你所要求的。

这个问题相当模糊,所以这可能没有帮助。

<!-- ONLY ONE INPUT FIELD IS NEEDED -->
<input id="SOMETHING" type="text" name="fixed" value="">

<input type="submit" name="Option one" onClick="firstbutton();" value="option one" />
<input type="submit" name="Option two" onClick="secondbutton();" value="option two" />
<input type="submit" name="Option three" onClick="thirdbutton();" value="option three" />
</form>
<script type="text/javascript">
var input1 = "whatever input 1 will be";
var input2 = "whatever input 2 will be";
var input3 = "whatever input 3 will be";
function firstbutton() {
document.getElementById('SOMETHING').value = input1;
}
function secondbutton() {
document.getElementById('SOMETHING').value = input2;
}
function thirdbutton() {
document.getElementById('SOMETHING').value = input3;
}
</script>

将三个提交分为三个单独的表单,并为每个表单赋予不同的id (form1, form2, form3)。这样就容易多了。如果将AJAX与这些表单挂钩,那么就不必担心链接到这些表单的其他页面。