页面上的第二个表单是使用第一个表单的action属性

时间:2014-06-26 19:18:18

标签: php html forms

我有一个包含两个表单的页面,第二个表单是使用第一个表单的action属性。代码:

<!-- mountain sites -->
<form name="form" action="shopsite.php" method="post" id="form">

<!-- sites pass alt tag to shopsite.php -->
<ul id="sites">
<tr>
<li><td class="" id="Hyland"><div><img id="imgHyland" onclick="this.src='radiotower.jpg';clearAck('Hyland');" src="radiotower.jpg" alt="Hyland" class="location" /><br/>Hyland</div></td></li>

</ul>
<div><input type="hidden" name="sitename" id="sitename" value="" /></div>
</form><!-- end first form -->


<!-- non-mountain sites -->
<form name="form-nm" action="shopsite-nm.php" method="post" id="form-nm">

<!-- sites pass alt tag to shopsite-nm.php -->
<ul id="sites">
<li><td class="" id="KMS"><div><img id="imgKMS" onclick="this.src='radiotower.jpg';clearAck('KMS');" src="radiotower.jpg" alt="KMS" class="location" /><br/>KMS</div></td></li>
</tr>
<div><input type="hidden" name="sitename" id="sitename" value="" /></div>
</form><!-- end second form -->

当我点击任一表格上的输入(输入是li标签)时,它会转到shopsite.php。第二种形式的输入应该到shopsite-nm.php。我研究在页面上使用多个表单来调用不同的php页面,并且据说它是可能的,尽管我发现的示例没有使用隐藏的输入。我不确定这是不是问题。

提前感谢您的任何帮助:)

编辑:网站名从两种表单正确传递。

编辑2:如果有更好的方法来构建它,我可以接受建议。我们的想法是每个表单都会显示一个包含其状态的站点列表,当用户点击某个站点时,会显示一个页面,其中包含有关该特定站点的更详细信息。最初只有一个表格包含所有网站,但最近添加了新网站,需要不同的信息显示,这正是我现在试图用第二种形式。

1 个答案:

答案 0 :(得分:0)

你能在这里使用JQuery吗?

$(document).ready(function() {
    $('#Hyland').click(function(e) {
        $.ajax({
            url: 'shopsite.php',
            type: 'POST',
            data: $('#form').serialize(),
            success: function(res) {
                //Do Something here
                console.log(res);
            },
            error: function(error) {
                //Do Something here
                console.log(res);
            }
        });
    });
});