2014-01-27 2 views
0

У меня есть форма для добавления адресов, в которых одно из полей, если я выберу город, отобразит местоположения города. мой add.ctp является:Cakephp не показывает все данные формы

<?php ?> 
<div id="body-content"> 
    <h1>Add Store Locations</h1> 
    <?php echo $form->create("GalStore",array("controller"=>"gal_stores","action"=>"add")); ?> 
    <?php echo $form->hidden("key",array("value"=>$key)); ?> 
    <table style='line-height:25px;' cellspacing="10px"> 
     <tr> 
      <td>Select Provider :</td> 
      <td> 
       <?php 
       $attributes = array("empty"=>false); 
       echo $form->select("GalStore.gal_provider_id",$gal_providers,null,$attributes); 
       ?> 
      </td> 
     </tr> 
     <tr> 
      <td>Address</td> 
      <td><?php echo $form->textarea("address",array("label"=>"")); ?></td> 
     </tr> 

     <tr> 
      <td>About</td> 
      <td><?php echo $form->textarea("GalStore.about",array("label"=>"")); ?></td> 
     </tr> 



     <tr> 
      <td>City</td> 
      <td><?php 
      $city_attributes = array("empty" => "-- Select City ---","id" => "locations_list"); 
      echo $form->select("GalStore.gal_location_id", $gal_locations,null,$city_attributes); ?> 

      </td> 
     </tr> 
     <tr> 
      <td>Location</td> 
      <td id="load_sublocations"> 

      </td> 
     </tr> 

     <tr> 
      <td>Contact Number</td> 
      <td><?php echo $form->input("contact_num",array("label"=>"")); ?></td> 
     </tr> 
     <tr> 
      <td>Other Info</td> 
      <td><?php echo $form->input("other_info",array("label"=>"")); ?></td> 
     </tr> 
     <tr> 
      <td></td> 
      <td><?php echo $form->end("Add"); ?></td> 
     </tr> 
    </table>  

    <h3>Existing Store locations</h3> 
    <div> 
     <?php 
     foreach($gal_stores as $store){ 
      echo "<div style='padding-bottom:10px'>";; 
      echo $store["GalStore"]["address"]." - ".$store["GalStore"]["city"]." - ".$store["GalStore"]["contact_num"]; 
      echo "</div>"; 
     } 
     ?> 
    </div> 
</div> 



<script> 
$('#locations_list').change(function(){ 

    $('#load_sublocations').empty(); 
    var gal_location_id = $('#locations_list').val(); 
    var url = "<?php echo $html->url(array("controller" => "gal_sublocations", "action" => "api_get_sublocations_by_location")); ?>"; 
    var data = "gal_location_id="+gal_location_id; 
    var html = ''; 


    $.ajax({ 
     type: "GET", 
     url: url, 
     data: data, 
     dataType: "json", 
     error: function(msg){ 
      alert('Oops ! Make a halt while we fixing the issue.'); 
     }, 
     success: function(msg){ 
      jQuery.each(msg.gal_sublocations, function(index, gal_sublocation) { 
       html += '<input type="checkbox" name="GalStore.gal_sublocation_id[]" value = "'+gal_sublocation.GalSublocation.id+'" />'+gal_sublocation.GalSublocation.name; 
       $('#load_sublocations').html(html); 
      }); 

     }    
    }); 

}); 

</script> 

Но когда я var_dump($this->data) он не показывает все поля формы, он выдает, как показано ниже:

array (size=1) 
    'GalStore' => 
    array (size=7) 
     'key' => string 'asdg213yt' (length=9) 
     'gal_provider_id' => string '237' (length=3) 
     'address' => string 'sdg sdf' (length=7) 
     'about' => string 's dfsdf' (length=7) 
     'gal_location_id' => string '16' (length=2) 
     'contact_num' => string '444' (length=3) 
     'other_info' => string '345' (length=3) 

район API:

function api_get_sublocations_by_location(){ 
     $this->autoRender = false; 
     Configure::write("debug",0); 


     $error = false; 
     $resp_type = (!isset($_GET["resp_type"]) || $_GET["resp_type"] == "") ? "json" : $_GET["resp_type"]; 

     $resp_arr = array(); 

     if(!isset($_GET["gal_location_id"]) || $_GET["gal_location_id"] == ""){ 
      $resp_arr["error"] = true; 
      $resp_arr["msg"] = "Invalid Location requested"; 
     }else{ 
      $gal_sublocations = $this->GalSublocation->getList($_GET["gal_location_id"],50,false); 

      //in case of any DB error 
      if(!$gal_sublocations){ 
       $resp["error"] = true; 
       $resp["msg"] = "Oops .. seems like something went wrong"; 
      }else{ 
       $resp["error"] = false; 
       $resp["gal_sublocations"] = $gal_sublocations; 
      }    
      return json_encode($resp); 

     } 
    } 

Почему он не показывает идентификаторы sublocation? Где я ошибаюсь? Пожалуйста помоги.

+0

пожалуйста показать код api_get_sublocations_by_location –

ответ

1

Я думаю, что ваши JS должны формировать поле ввода с именем, похожим на:

name="data[GalStore][gal_sublocation_id][]" 
+0

Большое спасибо lot..you спас меня! – Nitish