【问题标题】:how to include two submit buttons for a form with different action如何为具有不同操作的表单包含两个提交按钮
【发布时间】:2013-08-19 16:29:15
【问题描述】:

这是我的场景:

我的主页上有一个 html 表单,用户可以在其中输入数据并使用 post 方法提交表单。

<form  id="main" name="main" action="#text" method="post" > 


    //codes goes here


    <input  id="generate" type="submit"  name="script" value="create output" />

</form>

处理上述表格的PHP代码是

     <?php 

echo '<form action="#text" method="post">'; 

echo '<textarea onclick="this.select()" name="output_textarea" id="output_textarea" cols="100" rows="25" readonly>';

//above form inputs will echo in this textarea

<-------PHP codes for download here---->
<-------PHP codes for email here---->


<input type="submit" id="download"  value="Download" name="download"></input>
<input type="submit" id="send"  value="send" name="send"></input>

echo '</textarea>';
echo '</form>';
?>

我正在将表单输出回显到文本区域,我需要 下载按钮 一个电子邮件按钮

保存\发送文本区域。这是我面临的问题是执行下载 php 功能的第二页上的提交按钮,而不是电子邮件。

那么,如何为两个提交函数分配两个单独的函数?下载并发送电子邮件?

我在这里没有使用单独的 php 页面,而不是在我添加 html 的同一页面上使用 php 代码。

【问题讨论】:

标签: php html forms


【解决方案1】:

按钮仅在按下时才添加到 $_POST 中,并且一次只能按下一个按钮,

你可以这样做或类似的事情:-

if ( isset( $_POST['download'] ) ) {
    do_dowload_stuff();
}

if ( isset( $_POST['email'] ) ) {
    do_email_stuff();
}

【讨论】:

    【解决方案2】:

    将您的代码更改为:

    if(isset($_POST['download'])){
        // download code here
        echo "Download ".$_POST['output_textarea'];
    } elseif(isset($_POST['send'])){
        // email code here
        echo "Email ".$_POST['output_textarea'];
    }
    
    
    echo '<form action="#text" method="post">'; 
        echo '<textarea onclick="this.select()" name="output_textarea" id="output_textarea" cols="100" rows="25" readonly></textarea>';
        echo '<input type="submit" id="download"  value="Download" name="download"/>';
        echo '<input type="submit" id="send"  value="send" name="send"/>';
     echo '</form>';
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-13
      • 1970-01-01
      • 2012-08-09
      • 1970-01-01
      • 1970-01-01
      • 2016-06-19
      • 1970-01-01
      • 2013-01-14
      相关资源
      最近更新 更多