Question

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 ?

Was it helpful?

Solution 2

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'));

OTHER TIPS

You can set all sorts of html options for your button after label, as an array, like:

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top