简体   繁体   中英

How to set Javascript variable to php in Yii framework

Let me know to how to set Javascript variable "ad_field_id" to $form's hidden field in php. If its set successfully the save in DB process will be handled in MyController.php class

     <?php $form=$this->beginWidget('CActiveForm', array(
          'id'=>'tab-form-123',             
          'enableAjaxValidation' => false,
              'enableClientValidation' => true,
          'stateful' => true,
              'htmlOptions' => array ('enctype' => 'multipart/form-data'),
     )); ?>

       <?php echo $form->hiddenField($model, 'ad_field_id'); ?>
       <?php echo $form::submitButton('Save',array('submit'=>'BCFormFields')); ?>

    <?php $this->endWidget();?>


    <script src="<?php echo Yii::app()->request->baseUrl; ?>/js/yui-min.js"></script>
    <script>
    Y.DD.DDM.on('drag:drophit', function(e) {
    var drop = e.drop.get('node'),
        drag = e.drag.get('node');

    var ad_field_id = ['id: ' + e.drag.get('node').get('id')];        
    }
    </script>

Add an id to the hidden form element

<?php echo $form->hiddenField($model, 'ad_field_id', array('id' => 'frm_id')); ?>

then you can update your script to

var ad_field_id = ['id: ' + e.drag.get('node').get('id')];
document.getElementById('frm_id').value = ad_field_id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM