如何识别提交表单后点击的链接?

时间:2013-12-26 13:36:18

标签: php jquery forms submit form-submit

以下是表格:

<form id="transfer-questions-form" name="transfer_questions" action="{$control_url}modules/questions/transfer_questions.php" method="post" action="#">
    <input type="hidden" name="op" id="op" value="transfer question" >
      <div class="from-block">
        <div class="block-heading">
          <h3>From</h3>
        </div>
        <div class="form-fields">
          <ul>
            <li>
              <label>Subjects <span class="madatory">*</span></label>
              <div class="form-element">
                <select name="from_subject_id" id="from_subject_id" onchange="get_topics_by_subject(this.value, 'get_topics_by_subject_for_question_transfer_filter', '#from_topic_id'); return false;">
                <option value="">---Select---</option> 
                {foreach from=$all_subjects item=subjects key=key} 
                  <option value="{$subjects.subject_id}" {if $from_subject_id == $subjects.subject_id} selected="selected"{/if}>{$subjects.subject_name}</option>
                {/foreach}
            </select>
              </div>
            </li>
            <li>
              <label>Topics <span class="madatory">*</span></label>
              <div class="form-element">
                <select name="from_topic_id" id="from_topic_id">
               <option value="">---Select---</option> 
                  {foreach from=$all_from_topics item=topics key=key} 
                    <option value="{$topics.topic_id}" {if $from_topic_id==$topics.topic_id} selected="selected"{/if}>{$topics.topic_name}</option>
                  {/foreach}
             </select>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <div class="to-block">
        <div class="block-heading">
          <h3>To</h3>
        </div>
        <div class="form-fields">
          <ul>
            <li>
              <label>Subjects <span class="madatory">*</span></label>
              <div class="form-element">
                <select name="to_subject_id" id="to_subject_id" onchange="get_topics_by_subject(this.value, 'get_topics_by_subject_for_question_transfer_filter', '#to_topic_id'); return false;">
                <option value="">---Select---</option> 
                {foreach from=$all_subjects item=subjects key=key} 
                  <option value="{$subjects.subject_id}" {if $to_subject_id == $subjects.subject_id} selected="selected"{/if}>{$subjects.subject_name}</option>
                {/foreach}
            </select>
              </div>
            </li>
            <li>
              <label>Topics <span class="madatory">*</span></label>
              <div class="form-element">
                <select name="to_topic_id" id="to_topic_id">
               <option value="">---Select---</option> 
                  {foreach from=$all_to_topics item=topics key=key} 
                    <option value="{$topics.topic_id}" {if $to_topic_id==$topics.topic_id} selected="selected"{/if}>{$topics.topic_name}</option>
                  {/foreach}
             </select>
              </div>
            </li>
          </ul>
        </div>
      </div>
            <a href="#deletePopContentMove" class="c-btn fl-right submit_move_form">Move Questions</a>
      <a href="#deletePopContentCopy" class="c-btn fl-right submit_copy_form">Copy Questions</a>

    </form>
<div class="hidden">
  <div id="deletePopContentMove" class="c-popup">
    <h2 class="c-popup-header">Move Questions</h2>
    <div class="c-content">

        <p><strong>Do you really want to move the questions?</strong></p>

        <a href="#"class="c-btn">No</a><a href="#"class="c-btn confirm_submit_form">Yes</a> 
      </div>
  </div>
</div>

<div class="hidden">
  <div id="deletePopContentCopy" class="c-popup">
    <h2 class="c-popup-header">Copy Questions</h2>
    <div class="c-content">

        <p><strong>Do you really want to copy the questions?</strong></p>

        <a href="#"class="c-btn">No</a><a href="#"class="c-btn confirm_submit_form">Yes</a> 
      </div>
  </div>
</div>
<script language="javascript" type="text/javascript">

$(document).ready(function() {                                                   
  $(".submit_move_form").click(function(e) { 
    $(".submit_move_form").colorbox({inline:true, width:666});  
        $(".c-btn").bind('click', function(){
        $.colorbox.close();
      });
  });

  $(".submit_copy_form").click(function(e) { 
    $(".submit_copy_form").colorbox({inline:true, width:666});  
    $(".c-btn").bind('click', function(){
      $.colorbox.close();
    });
  });

$(".confirm_submit_form").click(function(e) { 
    document.transfer_questions.submit();
});

});
</script>

现在我想确定在提交表单后用户点击了哪个按钮(链接)。我没有得到如何实现它? 换句话说,我要确定Move Questions还是Copy Questions。有人可以帮我吗?提前致谢。

2 个答案:

答案 0 :(得分:1)

您可以在HTML中添加隐藏的输入:

<input type="hidden" id="action" name="action" value="" />

然后在jQuery函数中填充其值。 我们称之为“动作”,然后输入submit_move_form:

$("#action").val('move');

在submit_copy_form中:

$("#action").val('copy');

您只需检查$ _POST ['action']即可知道点击了哪个链接。

希望这有帮助!

答案 1 :(得分:0)

您可以尝试在按钮点击事件中设置一个标记值(示例移动问题= 0并复制问题= 1)然后,您可以使用“if”条件进行检查。

if(flag=='1')
{
//your code for copy questions
}
else
{
//your code for move questions 
}