我有一个外部Web表单,它将数据发布到我的控制器URL。数据以JSON字符串形式发送。从codeigniter中的外部表单获取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字符串格式。检查下面的答案。 – 2014-09-10 12:09:15