dr2898 2015-10-20 15:21
浏览 41
已采纳

在具有相同输入的另一个表单内形成

Is there a way to send exactly same variables to another page different from action of the form? I tried this structure but the second submit button did not work;

<form name="2" action="page2" method="post" >

<form name="1" action="page1" method="post" >

<input type="radio" name="radio" value="value1" >
<input type="radio" name="radio" value="value2" >
<input type="radio" name="radio" value="value3" >

<input type="submit" value="Submit1">

</form>

<input type="submit" value="Submit2">

</form>

The form 1 shows the information of inputs on the page1 and updates database also.

I want form 2 to show the information of inputs on the page2 only (no update of database).

Is that possible?

  • 写回答

1条回答 默认 最新

  • duanjianxu4288 2015-10-20 15:27
    关注

    You cannot have form inside another form , change your code like this.

    <form name="2" action="page2" method="post" >
        <input type="radio" name="radio" value="value1" >
        <input type="radio" name="radio" value="value2" >
        <input type="radio" name="radio" value="value3" >
        <input type="submit" value="Submit1" name="submit1">
        <input type="submit" value="Submit2" name="submit2">
    </form>
    

    Give different name for each submit button.

    in php

    if(isset($_POST['submit1'])){
        // submit1 is pressed
    }
    
    if(isset($_POST['submit1'])){
        // submit2 is pressed
    }
    

    Changing action dynamically.

    add class to submit buttons say, class="submit". ANd add id to form say id="my-form"

    $(".submit").change(function() {
          var action = $(this).val() == "submit1" ? "submit1.php : "submit2.php";
         $("#my-form").attr("action",  action);
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于php中URL传递GET全局变量的问题
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件