多个提交按钮php不同的操作 [英] Multiple submit buttons php different actions

查看:176
本文介绍了多个提交按钮php不同的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站开始,我想拥有2个单独的提交按钮,其中一个将获取输入的数据并对其进行一些计算以显示在同一屏幕上.我已经成功地与之合作了:

I have a website started where I want to have 2 separate submit buttons, one of which will take data entered and do some calculations to it to display on the same screen. I've got this successfully working with:

<form id="form1" name="form1" method="post" onsubmit="" onreset="" action="programname.php">
<input type="submit" name="calc" value="Find Angle">

然后我使用:

if (!isset($_POST['submit'])){
Do actions, display calculations}

现在,我想要第二个提交按钮,该按钮仍然可以捕获他们输入的数据,然后转到另一个地址.有没有一种优雅的方法可以做到这一点?

Now I want a second submit button that still grabs the data they entered but then goes to a different address. Is there an elegant way to do this?

推荐答案

您可以在新的Submit按钮中添加onclick方法,该方法将更改表单的操作,然后提交.

You could add an onclick method to the new submit button that will change the action of the form and then submit it.

<script type="text/javascript">
  function submitForm(action) {
    var form = document.getElementById('form1');
    form.action = action;
    form.submit();
  }
</script>

...

<form id="form1">
  <!-- ... -->
  <input type="button" onclick="submitForm('page1.php')" value="submit 1" />
  <input type="button" onclick="submitForm('page2.php')" value="submit 2" />
</form>

这篇关于多个提交按钮php不同的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆