Yii Framework Forum: where to put the submitButton in yii2 tab in case of deviding a form into multiple tabs - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

where to put the submitButton in yii2 tab in case of deviding a form into multiple tabs Rate Topic: -----

#1 User is offline   ikramadjissa 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 22-June 15

Posted 06 August 2015 - 09:28 AM

I have a form with many fields, on order to oragnize it I decided to divide it into multiple tabs using kartik tabX. I have divide my form view into many views that I call in the tab content property. My problem is the submit button. it is not working. I think I'm putting it in the wrong way.

Here is my code:

the views:
  • the tab view:


<?=Html::beginForm(['bien/acquisition'],'post');?>
<?=  TabsX::widget([
    'position' => TabsX::POS_ABOVE,
    'align' => TabsX::ALIGN_LEFT,
        'encodeLabels'=>false,
    'items' => [
        [
            'label' => 'Informations générales',
            'content' => $this->render('_formInfoGeneralAcquisition', ['model' => $model,
                                                                        'famille'=>$famille,
                                                                          'dat'=>$dat,
                                                                         'cmd'=>$cmd,
                                                                         'fact'=>$fact]),
            'active' => true,
        ],

        [
            'label' => 'Amortissement',
            'content' => $this->render('_formAmortAcquisition', ['model' => $model,'compte'=>$compte]),

            'options' => ['id' => 'myveryownID'],
        ],

    ],
]);
?>
 <div class="form-group">
            <?= Html::SubmitButton( 'Enregistrer bien', ['class' => 'btn btn-success', 'id'=> 'm']) ?>    
    </div>



 <?= Html::endForm();?>



_formInfoGeneralAcquisition view (first view):

<?php $form = ActiveForm::begin(['id' => 'acquisition-form']); ?>

//My fields
        <?php ActiveForm::end(); ?>



_formAmortAcquisition view (second view):
I have made the same thing for this second view.
<?php $form = ActiveForm::begin(['id' => 'acquisition-form']); ?>

//My fields

    <?php ActiveForm::end(); ?>

0

#2 User is offline   Bizley 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 922
  • Joined: 29-July 14
  • Location:Wrocław

Posted 07 August 2015 - 04:05 AM

It looks like you have got multiple forms in one form and you try to submit the forms using the one big form submit button.

There are two solutions:
1) Use js to send multiple forms by clicking "big form" submit button.
2) Don't wrap the tab view form fields in <form> tag so these can be taken as "big form" fields and therefor submitted with "big form" button.
http://bizley.pl ʕ•ᴥ•ʔ
0

#3 User is offline   ikramadjissa 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 22-June 15

Posted 09 August 2015 - 05:09 AM

Dear Bizley,
The problem is exactly as you mentionned. I get the data only from the first form and not from the other.
I tried the second solution but it is not working.
For the first solution ,I modified the forms IDs and I have added this js code to the tab view, but still not working.

<?php
$script = <<< JS
$(function () {
$('#m').click(function(){
document.getElementById("acquisition-form1").submit();
document.getElementById("acquisition-form2").submit();
});

});

JS;
$this->registerJs($script);
?>
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users