donglu5728 2012-07-20 07:35
浏览 20
已采纳

HTML - 形成最佳实践

It's OK to have a form with more submit buttons? I mean I have a form which contains some input fields and a table and 3 buttons which will export some information in different formats

<form id="form1" name="form1" method="post" >
    <label for="country"><strong>Countries: </strong></label><br />
    <select id="country" name="country">
      <?php
      //some php code here
      ?>
    </select> 
    <br />
    <br/>
    <label for="start_date"><strong>Start date: </strong></label><br />
    <input name="start_date" type="text" id="start_date" value="<?php if(!empty($start))echo $start; ?>" size="20" />
    <br />
    <br />  
    <label for="stop_date"><strong>Stop date: </strong></label><br />
    <input name="stop_date" type="text" id="stop_date" value="<?php if(!empty($stop)) echo $stop; ?>" size="20" />
    <br />
    <br />
        <input type="submit" name="fill_table" value="Retrieve data" /> 

    <div id="table">
      <h1>&nbsp;</h1>
      <hr />
      <h2>Sales Report</h2>
        <table class="display" id="data_table" >
          <thead>
              <tr>
                <th>Product</th>
                <th>Date</th>
                <th>Quantity</th>
              </tr>
          </thead>
          <tbody>
            <?php
                //some php code here
            ?>
          </tbody>
        </table>
        <br />
        <br />
        <br />
        <input type="submit" class="button" name="export_xls" value="Export xls" />
        <input style="margin-left:10px;" type="submit" name="export_html" value="Export html" />
  </form>

Is it ok to do it this way or should i make 3 forms each one having a particular submit button? Each time i press a submit button I'm intrested in the input fields :start_date, stop_date and the selected item from "country". P.S. I want to know if it's optimal and how other programmers would handle this stuff

  • 写回答

4条回答 默认 最新

  • drwkqwa82140 2012-07-20 07:42
    关注

    I don't think it's a bad idea. But all your submit buttons must have the same name attribute.

    Check out this

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?