使用codeigniter一次发送两个不同的表单

时间:2017-11-04 09:37:30

标签: javascript codeigniter

我试图一键发送两种不同的表格。第一个表单将用于发送form_multipart,另一个表单将通过javascript。为什么javascript?因为这是我知道在codeigniter中发送batchinsert表单的唯一方法。如果独立执行,这两个工作正常。您如何建议以正确的方式正确组合表格?我需要发送代码吗?

查看

void

控制器 公共函数signupPost()     {

<?php 
    $attributes = array("name" => "signupform");
    $hidden = array('userId' => 'userId', 'userType' => 'client', 'branchId' => 'CDO1', 'position' => 'none', 'userfile' => 'userfile');
    echo form_open_multipart("Client_Dashboard/signupPost", $attributes, $hidden);
?>

enter image description here

查看

    if ($this->form_validation->run('signup') == FALSE) {
        //fails wont continue to next page
        $this->signup_view();
    } else {
        //insert data into the database
        $data = array(
            'userId' => $this->input->post('userId'),
            'password' => $this->input->post('password'),
            'emailAddress' => $this->input->post('emailAddress'),
            'firstName' => $this->input->post('firstName'),
            'lastName' => $this->input->post('lastName'),
            'middleInitial' => $this->input->post('middleInitial'),
            'gender' => $this->input->post('gender'),
            'address' => $this->input->post('address'),
            'lengthOfResidency' => $this->input->post('lengthOfResidency'),
            'contactNo' => $this->input->post('contactNo'),
            'dateOfBirth' => $this->input->post('dateOfBirth'),
            'maritalStatus' => $this->input->post('maritalStatus'),
            'citizenship' => $this->input->post('citizenship'),
            'noOfDependents' => $this->input->post('noOfDependents'),
            'userType'  => $this->input->post('userType'),
            'position'  => $this->input->post('position'),
            'branchId'  => $this->input->post('branchId'),
            'UserFile' => $this->uploadImage()
            );
        //user data has successfully signed up
        $this->User->signup_client($data);
        redirect('http://localhost/***/index.php/****','refresh');
    }
}

控制器

<script>
    ("#frm_submit").on('submit', function (e) {
                 e.preventDefault();
                 $.ajax({
                    url: '<?php //echo base_url() ?>index.php/Client_Dashboard/income_batchInsert',
                     type: 'POST',
                     data: $("#frm_submit").serialize()
                 }).always(function (response){
                     var r = (response.trim());
                    if(r == 1){
                         $(".alert-success").show();
                    }
                     else{
                         $(".alert-danger").show();
                    }
                 });
             });
</script>

模型

public function income_batchInsert()
    {
        $result = $this->foo_inc->income_batchInsert($_POST);
            if($result){
                echo 1;
            }
            else{
                echo 0;
            }
            exit;
    }

enter image description here enter image description here

0 个答案:

没有答案