$clients = $this->requestAction('/clients/get_names');
$client_array = array();
foreach ($clients as $client) {
$client_array[$client['Client']['client_name']] = $client['Client']['client_name'];
}
echo $this->Form->input('title', array(
'name' => 'title',
'options' => $client_array,
'empty' => 'Select a client',
'label' => ''
));
HTML OUTPUT
<select name="title" id="title">
<option value="">Select a client</option>
<option value="Jennifer Lopez">Jennifer Lopez</option>
</select>
点击提交它将数据发送到我的JS文件
$.post( "save",
{ action: "save",
start: calEvent.start.getTime()/1000,
end: calEvent.end.getTime()/1000,
title: calEvent.title,
body: calEvent.body,
id: calEvent.id
});
接收数据并放入数据库
public function save() {
$this->layout = 'ajax';
$title = $_REQUEST['title']; // tried $this->request->data allready
$body = $_REQUEST['body'];
$start_time = (int)$_REQUEST['start'];
$start_time = $start_time + 60*60;
$end_time = (int)$_REQUEST['end'];
$end_time = $end_time + 60*60;
$start = date('c',$start_time);
$end = date('c',$end_time);
$sql = "INSERT INTO agendas (title,body,start,end) VALUES ('$title','$body','$start','$end')";
$this->Agenda->query($sql);
exit(0);
}
现在的问题是当选择“Jennifer Lopez”时,它不会使用表单发送值。
所以在这种情况下它不会将“Jennifer Lopez”发布到我的数据库中。如何使用表单发送选择?
我是初学者,所以我处于学习模式!
答案 0 :(得分:0)
您确定在AJAX帖子中发送了title: calEvent.title
吗?仔细检查那部分。可能是calEvent.title
的jQuery选择器错误。