我想创建一个简单的Facebook应用程序,其形式如下:
https://apps.facebook.com/koweb_test_form/
问题是当它第一次进入发布给它的页面时,由于它是一个表单,它将检查发布数据
因此,如何防止发布/我对此的逻辑感到困惑,所以我需要更改实现
这是控制器代码:
public function index()
{
$data = array();
if ($this->input->server('REQUEST_METHOD') === 'POST') {
$this->form_validation->set_rules('q1_ans', 'Answer for question 1', 'required');
$this->form_validation->set_rules('q2_ans', 'Answer for question 2', 'required');
$this->form_validation->set_error_delimiters('<div class="alert alert-danger"><a class="close" data-dismiss="alert">x</a><strong>', '</strong></div>');
if ($this->form_validation->run()) {
$data_insert = array(
'q1_ans' => $this->input->post('q1_ans'),
'q2_ans' => $this->input->post('q2_ans'),
'fb_id' => $this->input->post('fb_id'),
'name' => $this->input->post('name')
);
if ($this->input->post('email') != "") {
$data_insert['email'] = $this->input->post('email');
}
$data['flash_message'] = $this->Ans_model->add_ans($data_insert);
}
}
$this->load->view('home',$data);
}
对于前端,它只是一个简单的表单代码
非常感谢您的帮助