girish
girish

Reputation: 305

Serialize form data from bootstrap modal in Yii Framework

I am currently using a CActiveForm within a Bootstrap Modal.

The Modal pop up displays the data correctly but when i edit some data within the form and try to serialize it, it still displays the old data. There must be some caching mechanism I am unaware of.

Below is my code:

Controller:

public function actionEditChequeRefund($id){
    $model = Refund::model()->find('id=:id', array(':id' => $id));  

    echo $this->renderPartial('_refund', array('model' => $model);
    Yii::app()->end();
}

View: _refund.php

            <div class="form">

            <?php
            $form = $this->beginWidget('CActiveForm', array(
                'id' => 'edit-refund-form',                 
                'enableAjaxValidation' => false,
            ));
            ?>

            <?php echo $form->errorSummary($model); ?>  



            <div class="input">
                    <?php echo $form->labelEx($model, 'name'); ?>
                    <?php echo $form->textField($model, 'name'); ?>
                    <?php echo $form->error($model, 'name'); ?>
            </div>

            <div class="input">
                    <?php echo $form->labelEx($model, 'amount'); ?>
                    <?php echo $form->textField($model, 'amount'); ?>
                    <?php echo $form->error($model, 'amount'); ?>
            </div>

            <div class="input">
                    <?php echo $form->labelEx($model, 'mobile'); ?>
                    <?php echo $form->textField($model, 'mobile'); ?>
                    <?php echo $form->error($model, 'mobile'); ?>
            </div>



            <input type="button" class='button blue edit_refund' value="Save & Close"/>


            <?php $this->endWidget();?>            
        </div><!-- form -->

<script>
$('.edit_refund').click(function(){
    var datas = $("#edit-refund-form").serialize(); 
    alert(datas);   
    return false;
});
</script>

Upvotes: 2

Views: 1068

Answers (1)

Mihai P.
Mihai P.

Reputation: 9357

I read the question again. Here is your problem. When creating a modal part of the div is copied inside the actual dialog box. This means that you actually have 2 times elements with the id edit-refund-form. As a quick solution try selecting the form like this $(".ui-dialog #edit-refund-form").serialize();

Upvotes: 3

Related Questions