Yii Controller Action Does Not Recorgnize Post Data From Auto Generated Fields After Dom

Hello, am really having a bad time here getting solution to my problem.

This is my case :

I have html form fields that i dynamically generated using jquery and html form (Add more fields ), (remove field).

The html name attributes will be posted to my controller action using AJAX. The data will be sent in JSON and also accept response in JSON.

The problem is, Controller Myaction accepts my request as Yii::app()->request->isAjaxRequest. but data sent through ajax are not captured by the controller action.

This is my code





VIEW

<?php /** @var BootActiveForm $form */

    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(

    'id'=>'job-competency-profile-form',

        'type' => 'inline',

        'enableAjaxValidation'=>true,

        //'clientOptions'=>array('validateOnSubmit'=>true), 

        'htmlOptions'=>array('class'=>'',

                              // 'onkeypress'=>" if(event.keyCode == 13){ sendvalue(); } " /* Do ajax call when user presses enter key */

                             ),

)); ?>


<div class="well" id="dynamicRow></div>

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


<script type="text/javascript">

var validitem = 0;

function addRow(frm) {

	var rowNum = event.target.id;

        validitem++;

        //alert(event.target.id);

	var row = '<div id="dynamic'+validitem+'"> <div class="input-prepend"><span class="add-on"><i class="icon-male"></i></span> <input type="hidden" name="['+validitem+']Kjc[kjc]" id="result_kjc'+validitem+'" value="" /> <input class="span3" placeholder="Key Job Competency" name="cdata" id="Kjc_kjc'+validitem+'" type="text" maxlength="250" value=""/></div>  <div class="input-prepend"><span class="add-on"><i class="icon-male"></i></span> <input type="hidden" name="['+validitem+']Kjc[plevel]" id="result_plevel'+validitem+'" value="" /> <input class="span2" placeholder="Proficiency Level" name="pdata'+validitem+'" id="plevel'+validitem+'" type="text" maxlength="250" value=""/></div> <button id="remove'+validitem+'" name="remove'+validitem+'" onclick="removeRow('+validitem+');" class="btn btn-small" type="button">Remove</button> <br/> </div>';

         var savebtn = '<button id="save'+rowNum+'" name="saveval'+rowNum+'" class="btn btn-success btn-small" type="button" onclick="saveval('+rowNum+');">Save</button>'; // save button

         $('#dynamicRow'+rowNum+'').append(row);

         $('#dynamicRow'+rowNum+'').append(savebtn);

         var btn = $('button#save'+rowNum+'').size();

          if(btn > 1) {   

                   $('#dynamicRow'+rowNum+'').find('button#save'+rowNum+':first').remove(); 

                  //alert("HI");

                   }

        // $( "#plevel"+validitem+"" ).autocomplete({"button[name*='addmore']"

        $("input[id*='plevel']").autocomplete({

         source: function( request, response) {

         $.ajax({

            type: "GET",

          url: "<?php echo Yii::app()->createUrl('jcprofile/jcp/getproficiency');?>",

          dataType: "json",

          data: {

            featureClass: "P",

            style: "full",

            maxRows: 200,

            name_startsWith: request.term

          },

          success: function( data ) {

            response( $.map( data, function( item ) {

              return {

                label: item.name,

                value: item.id

              }

            }));

          }

        });

      },

      minLength: 2,

      select: function( event, ui ) {

      event.preventDefault() // <--- Prevent the value from being inserted.

       var getid = event.target.id;   

       alert(getid);

      $("#"+getid+"").val(ui.item.label);

      $('#result_plevel'+validitem+'').val(ui.item.value);

      

     },

      open: function() {

        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );

      },

      close: function() {

        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );

      }

    });

         

         // end ajax proficiency level autocomplete

        $( '#Kjc_kjc'+validitem+'' ).autocomplete({

        //$( "input[id*='Kjc_kjc']" ).autocomplete({

         source: function( request, response ) {

        $.ajax({

            type: "GET",

          url: "<?php echo Yii::app()->createUrl('jcprofile/jcp/getCompetency');?>",

          dataType: "json",

          data: {

            featureClass: "P",

            style: "full",

            maxRows: 200,

            name_startsWith: request.term

          },

          success: function( data ) {

            response( $.map( data, function( item ) {

              return {

                label: item.competency_name,

                value: item.id

              }

            }));

          }

        });

      },

      minLength: 2,

      select: function( event, ui ) {

      event.preventDefault() // <--- Prevent the value from being inserted.

      var getcid = event.target.id; 

      $("#"+getcid+"").val(ui.item.label);

      $('#result_kjc'+validitem+'').val(ui.item.value);

       // log( ui.item ?

        //  "Selected: " + ui.item.label : "Nothing selected, input was " + this.value);

     },

      open: function() {

        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );

      },

      close: function() {

        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );

      }

    });

         //end competency list ajax auto complete

    }

    for(i=0;i<=7; i++);

    $("button[name*='addmore']" ).click(function(event) {

      if(event.target.id != ""){

        addRow(this.form);

        //alert(event.target.id);

      }

      });

  


        function removeRow(rnum) {

             $("button[name*='remove']").click(function(event) {

              var id = $(this).parents('div:eq(0)').attr('id');

             $('#'+id+'').remove();

            //event.preventDefault();

            });

        }

</script>




MY COntroller

 public function actionRequestdata()

        {

                $model=new JobcompetencyProfile;

                $kjc = new Kjc;

                $item = array();

               

                if(Yii::app()->request->isAjaxRequest && isset($_POST["Kjc"]))

               {

                     $data = $_POST['Kjc']['kjc'];

                     $decode = json_decode($data, true);

                     echo json_encode($data);

                      Yii::app()->end();  

                  // echo json_encode(var_dump($data));

                   /* if(isset($_POST['Kjc']) && is_array($_POST['Kjc']))

                    {

                     $kjc->attributes = $_POST['Kjc'];

                     echo json_encode(var_dump($_POST));

                       

                    }*/

               }

        }




Please help me. nothing get posted to my controller action method



Solved!! Thanks