0

基本的に、マルチパートフォームのコントローラーに、投稿データをプレビューや編集などの他の機能に提供する単一の機能を持たせたいと考えています。

機能は以下です。

function get_post_data()
{
  $post_data_array = array();
  // declaration of all form field names
  $variable_array = array('form_field_1', 'form_field_2', ... 'form_field_n');

  for ($i = 0; $i < count($variable_array); $i++) {
    $variable_value = $this->input->post($variable_array[$i]);
    // turn them into an easy-to-use array
    $post_data_array[$variable_array[$i]] = $variable_value;
  }
  return $post_data_array;
}

そのため、関数は次のようにアクセスします。

function show_preview_form()
{
  $this->load->view('preview_form_view', $this->get_post_data() );
}

function send_to_database()
{
  $data_array = $this->get_post_data();
  $this->Model->insert_to_database($data_array['form_field_1'], ...);
}

現在、動作しません。Firebug はステータスを返し500 Internal Status Errorます。これを解決する方法を知っていますか?

get_post_datalongを必要とするすべての関数でlong を繰り返したくありません。

4

3 に答える 3

1

なぜあなたはこれをやっている?

投稿データを配列として取得できます..

$post_data = $this->input->post();

...

http://ellislab.com/codeigniter/user-guide/libraries/input.html

于 2013-02-14T06:19:41.343 に答える
0

$post_data_array値を追加する前に、に空の配列を割り当てる必要があります。

関数の先頭にget_post_data追加$post_data_array = array();

アップデート:

URLから直接アクセスできないよう に変更get_post_dataすることもおそらく良い考えです。http://ellislab.com/codeigniter/user-guide/general/controllers.html#private_get_post_data

于 2013-02-14T00:24:21.807 に答える
0

はい、単に使用できます

               $this->input->post(); 

入力フィールド投稿データを取得します。さらに、次のように set_rules で入力投稿フィールドを確認できます

                     $this->form_validation->set_rules('userName','Username','trim|regex_match[/^[a-z,0-9,A-Z_ ]{5,35}$/]|required|xss_clean');
    $this->form_validation->set_rules('userFirstName', 'First name','trim|regex_match[/^[a-z,0-9,A-Z_ ]{5,35}$/]|required|xss_clean');
    $this->form_validation->set_rules('userLastName', 'Last name','trim|regex_match[/^[a-z,0-9,A-Z_ ]{5,35}$/]|required|xss_clean');
    $this->form_validation->set_rules('userEmail', 'Email', 'trim|regex_match[/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/]|required|xss_clean');
    $this->form_validation->set_rules('userPass', 'Password', 'trim|regex_match[/^[a-z,0-9,A-Z]{5,35}$/]|required|xss_clean|md5|callback_check_database');
    if ($this->form_validation->run() == FALSE) {
        //your view to show if validation is false
    } else {
         $user_name = $this->input->post('userName');
        $userfname = $this->input->post('userFirstName');
        $userlname = $this->input->post('userLastName');
        $useremail = $this->input->post('userEmail');
        $userpass = $this->input->post('userPass');
        }
于 2014-07-07T11:39:44.047 に答える