我有一個外部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