修复Cakephp Form FIeld类型单选按钮中的选项

我正在使用Cakephp代码

<?php foreach ($viewfields as $r): if($r['Attribute']['type']=='radio') { 

?>

   jQuery.noConflict(); jQuery(document).ready(function($){ $("#"+).each(function() { type= ""; 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  input('field', array( 'type' => 'radio','legend'=>$r['Attribute']['label'], 'separator' => '--separator--', 'options' => array() )); }//if php type == radio endforeach; ?> 

警报(i.choice); /警告我标签性别的选择为男性和女性以及标签“体验为是和否..

如何将男性和女性放在’options’=> array()..请告诉我……

选择是由客户端提取的(即在浏览器上运行的JavaScript),因此您不能在服务器端的PHP代码中使用它们(即CakePHP FormHelper)。

上面的PHP代码一旦运行,就会生成一个带有JavaScript块的页面。 这将发送到用户的浏览器。 页面加载后,它会从服务器请求一个选项列表。

此时编辑已发送到客户端的页面为时已晚,除非您使用更多JavaScript。

您可能需要考虑在CakePHP控制器操作中获取这些选项,然后在视图中传递它们。 这将允许您在将页面发送到客户端之前在FormHelper中的视图中使用它们。

你可以试试这个。

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