yii CHtml submitButtion

时间:2013-10-22 04:20:35

标签: php yii yii-chtml

我开始学习yii并尝试对其他人的代码进行一些更改。我想将submitButton函数添加到其他按钮(完成提交按钮)

          if ($page == $pageCount) {

            echo CHtml::submitButton("Save", array('class' => 'btn', 'name' => 'files', 'title' => 'Save the updates to these files'));

            ?>
            <form action="/dataset/submit" method="post" style="display:inline">
                <input type="hidden" name="file" value="file">
                <input type="submit" value="Complete submission" class="btn-green" title="Submit changes to file details."/>
            </form>
  1. 我知道'文件'是需要提交的所有值,但点击操作在哪里?
  2. 哪个操作与此按钮有关?

     echo CHtml::submitButton("Save", array('class' => 'btn', 'name' => 'files', 'title' => 'Save the updates to these files'));
    
  3. 如何将“保存”按钮功能添加到“完成提交”按钮?

2 个答案:

答案 0 :(得分:1)

您可以在标签后为按钮设置各种html选项,如数组,如:

echo CHtml::submitButton('Submit' , array(
    'onclick' => 'yourFunction()',
    'id' => 'btnSubmit',
    .
    .
    .
));

http://www.yiiframework.com/doc/api/1.1/CHtml#submitButton-detail

答案 1 :(得分:0)

@tinyByte的代码是一种可能的解决方案。

我补充其他可能性:

<script>
$(document).ready(function(){

    // Controll submit form event
    $( "#myForm" ).submit(function() {
      alert( "Handler for .submit() called." );
    });

    // Controll click by javascript
    $( "#btSubmit" ).click(function(event) {
      event.preventDefault(); // Stop default behavior for submit button.
      $( "#myForm" ).submit(); // Manually run submit
    });

});
</script>

查看表单:(向元素添加ID)

<form id="myForm" action="/dataset/submit" method="post" style="display:inline">
    <input type="hidden" name="file" value="file">
    <input type="submit" id="btSubmit" value="Complete submission" class="btn-green" title="Submit changes to file details."/>
</form>

<强>编辑:

您还可以在CHtml提交按钮上处理点击事件,添加ID,如下所示:

CHtml::submitButton("Save", array('id' => 'btSubmit', 'class' => 'btn', 'name' => 'files', 'title' => 'Save the updates to these files'));