0

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>
4
  • document.getElementById('id').value='new value'; ? Commented Jan 6, 2014 at 11:38
  • var ad_field_id = ['id: ' + e.drag.get('node').get('id')]; this ad_field is to be hidden field.i tried this code but it could not post in controller Commented Jan 6, 2014 at 11:44
  • i need to set/pass JS variable ad_field_id to <?php echo $form->hiddenField($model, 'ad_field_id'); ?>. Pls help to achieve this Commented Jan 6, 2014 at 11:55
  • document.getElementsByName('ad_field_id').value=ad_field_id; when i alert this statement , the variable is set properly i expected. but in controller var_dump($_POST) displays ad_field_id as null Commented Jan 6, 2014 at 12:51

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.