Search code examples
phpyiiyii-chtml

yii CHtml submitButtion


I start learning yii and try to make some changes in others' code. I want to add the submitButton function into other button (Complete submission button)

          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. I know the 'files' is all values need submit, but where is click action ?
  2. Which action is related to this button?

     echo CHtml::submitButton("Save", array('class' => 'btn', 'name' => 'files', 'title' => 'Save the updates to these files'));
    
  3. How can i add the Save button function into the Complete submission button ?


Solution

  • The code of @tinyByte it's a possible solution.

    I add other possibility:

    <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>
    

    View Form: (Add ids to the elements)

    <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>
    

    Edited:

    You can also handle the click event on the CHtml submit button adding a ID, like this:

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