Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 两个html表单操作_Php_Html_Forms - Fatal编程技术网

Php 两个html表单操作

Php 两个html表单操作,php,html,forms,Php,Html,Forms,是否可以创建两个表单动作?一个应该操作一个.php页面,另一个应该操作同一页面上的脚本 <form method="post" action=""> // Input fields here <input type="submit" name="calculate" value="Calculate price"> // Form should perform the calculation script below (not attached here

是否可以创建两个表单动作?一个应该操作一个.php页面,另一个应该操作同一页面上的脚本

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

// Input fields here

<input type="submit" name="calculate" value="Calculate price">
       // Form should perform the calculation script below (not attached here)

<input type="submit" name="order" value="Order">
       // Form should perform the action 'order.php'

</form>

//此处输入字段
//表单应执行以下计算脚本(此处未附加)
//表单应该执行“order.php”操作

搜索了很长时间,但找不到解决方案。有人知道如何解决此问题吗?

如果您希望表单中的按钮执行提交表单以外的操作,请将其类型设置为
按钮

<input type="button" name="calculate" value="Calculate price">


然后将单击处理程序附加到按钮以运行脚本。

如果希望表单中的按钮执行提交表单以外的操作,请将其类型设置为
按钮

<input type="button" name="calculate" value="Calculate price">


然后在按钮上附加一个点击处理程序来运行脚本。

假设您有一个事件将导致此更改,是的,但使用javascript。 例如:


假设您有一个将导致此更改的事件,是的,但使用javascript。 例如:


您可以尝试以下方法:

<script type="text/javascript">
   function SubmitForm()
   {
   if(document.pressed == 'Calculate price')
   {
      document.myform.action ="calculate.php";
   }
   else
      if(document.pressed == 'Order')
      {
         document.myform.action ="order.php";
      }
      return true;
   }
</script>
<form method="post" onsubmit="return SubmitForm();">

 // Input fields here

   <input type="submit" name="operation" onclick="document.pressed=this.value" value="Calculate price">
   // Form should perform the calculation script below (not attached here)

   <input type="submit" name="operation" onclick="document.pressed=this.value" value="Order">
   // Form should perform the action 'order.php'

</form>

函数SubmitForm()
{
如果(document.pressed==“计算价格”)
{
document.myform.action=“calculate.php”;
}
其他的
如果(document.pressed=='Order')
{
document.myform.action=“order.php”;
}
返回true;
}
//此处输入字段
//表单应执行以下计算脚本(此处未附加)
//表单应该执行“order.php”操作
因此,当您提交时,触发一个函数来捕获您的按钮值并设置表单操作


在这种情况下,您可以将计算脚本放在php文件中。

您可以尝试以下方法:

<script type="text/javascript">
   function SubmitForm()
   {
   if(document.pressed == 'Calculate price')
   {
      document.myform.action ="calculate.php";
   }
   else
      if(document.pressed == 'Order')
      {
         document.myform.action ="order.php";
      }
      return true;
   }
</script>
<form method="post" onsubmit="return SubmitForm();">

 // Input fields here

   <input type="submit" name="operation" onclick="document.pressed=this.value" value="Calculate price">
   // Form should perform the calculation script below (not attached here)

   <input type="submit" name="operation" onclick="document.pressed=this.value" value="Order">
   // Form should perform the action 'order.php'

</form>

函数SubmitForm()
{
如果(document.pressed==“计算价格”)
{
document.myform.action=“calculate.php”;
}
其他的
如果(document.pressed=='Order')
{
document.myform.action=“order.php”;
}
返回true;
}
//此处输入字段
//表单应执行以下计算脚本(此处未附加)
//表单应该执行“order.php”操作
因此,当您提交时,触发一个函数来捕获您的按钮值并设置表单操作


在这种情况下,您可以将计算脚本放在php文件中。

您需要两个不同的表单使用由onclick事件触发的JavaScript动态重新分配操作(您需要通过onsubmit调用返回false的函数等方式禁用表单提交)?查看代码,第一个按钮只是执行一个脚本,对吗?这不需要是submit类型的输入。只需单击运行js。您需要两个不同的表单使用JavaScript动态地重新分配操作,由onclick事件触发(您需要通过onsubmit调用返回false的函数之类的方式禁用表单提交)?查看代码,第一个按钮只执行一个脚本,对吗?这不需要是submit类型的输入。只需点击运行js。我已经将Calcute按钮的输入类型更改为“button”,但现在脚本不再工作了?当输入设置为“提交”时,它确实起作用了(顺便说一下,这两个按钮)?你能澄清一下,当你说“执行计算脚本”时,你指的是一个javascript函数吗?@KevinHamer如果你必须在按钮上附加一个点击处理程序,你是在使用提交处理程序来检测按钮按下吗?试着弄清楚这一点。。我的代码会是什么样子?我想我已经得到了。。。一切正常后,我们将尽快发布正确的代码!我已经将Calcute按钮的输入类型更改为“button”,但现在脚本不再工作了?当输入设置为“提交”时,它确实起作用了(顺便说一下,这两个按钮)?你能澄清一下,当你说“执行计算脚本”时,你指的是一个javascript函数吗?@KevinHamer如果你必须在按钮上附加一个点击处理程序,你是在使用提交处理程序来检测按钮按下吗?试着弄清楚这一点。。我的代码会是什么样子?我想我已经得到了。。。一切正常后,我们将尽快发布正确的代码!