修復

2009-09-08 48 views
0

我有CakePHP的代碼一樣修復

<?php foreach ($viewfields as $r): 

          if($r['Attribute']['type']=='radio') 
      { 

>

<script type="text/javascript"> 
    jQuery.noConflict(); 
    jQuery(document).ready(function($){ 


    $("#"+<?=$r['Attribute']['id'];?>).each(function() { 

    type= "<?=$r['Attribute']['type'];?>"; 
    attribute_id="<?=$r['Attribute']['id'];?>"; 
if(type=="radio") 
{ 
    var ht = $.ajax({ 
    type: "GET", 
    url: "http://localhost/FormBuilder/index.php/forms/viewChoices/"+attribute_id, 
    async: false 
    }).responseText; 



     var myObject = eval('(' + ht + ')'); 

var data = myObject;var j=0; 
$.map(data.choices, function(i){ j++; 
alert(i.choice); 
    return i.choice;}); 
    }//type==radio 
     });//each 
});//jquery 

</script> 


<?php 


     echo $form->input('field', array(
     'type' => 'radio','legend'=>$r['Attribute']['label'], 
     'separator' => '--separator--', 
     'options' => array() 
    )); 



}//if php type == radio 

endforeach; ?> 

警報(i.choice)在CakePHP的表單字段的選項類型單選按鈕;?/通知我的選擇,爲標籤性別爲男,女 和標籤「經驗yes和no ..

如何放置男性和女性在‘選項’=>陣列()..please建議我...

+0

duplicate:http://stackoverflow.com/questions/1393512/querying-inside-form-input-array – deizel 2009-09-10 13:06:14

回答

0

這些選擇是由客戶端(即。 JavaScript在瀏覽器上運行),所以你不能在你的服務器端PHP代碼中使用它們(即CakePHP FormHelper)。

上面的PHP代碼一旦運行,就會生成一個帶有JavaScript塊的頁面。這被髮送到用戶的瀏覽器。一旦頁面加載完成,它會向服務器請求一個選項列表。

現在編輯已發送給客戶端的頁面已經太晚了,除非您使用更多的JavaScript。

您可能想考慮在CakePHP控制器操作中獲取這些選擇,然後在視圖中傳遞它們。這將允許您也可以在頁面發送給客戶端之前在FormHelper的視圖中使用它們。

0

你可以試試這個。

 
'options' => array('Male'=>'Male', 'Female'=>'Female')