【发布时间】:2014-09-10 10:31:13
【问题描述】:
我有一个将数据发布到我的控制器 URL 的外部 Web 表单。数据以 JSON 字符串形式发送。
我需要做的是获取 JSON 字符串中的各个值并将它们添加到我的数据库中。但是,我在获取发布的值和解码它们时遇到了一些麻烦。
这是我尝试过的代码 - 任何帮助将不胜感激谢谢。
public function index() {
$this->load->view('lead');
$form_data = array(
'firstname' => json_decode($this->input->post('first_name')),
'lastname' =>json_decode($this->input->post('last_name')),
'number' =>json_decode($this->input->post('phone_number')),
'email' =>json_decode($this->input->post('email')),
'suburb' =>json_decode($this->input->post('suburb')),
'state' =>json_decode($this->input->post('state')),
'enquiry' =>json_decode($this->input->post('enquiry'))
);
// run insert model to write data to db
if ($this->AddLeadModel->SaveForm($form_data) == TRUE) // the information has therefore been successfully saved in the db { //Do something if successful }
【问题讨论】:
-
请检查 JSON 字符串格式。检查下面的答案。
标签: php json codeigniter