Codeigniter:提交的表单不显示值

时间:2011-04-14 08:11:26

标签: php codeigniter

请访问以下链接:Demo link for problem

您可以查看该表单未显示提交的值而不上传文件。

以下是表单代码:

<form id="frm" name="frm"  method="post" enctype="multipart/form-data">
            <fieldset class="fieldset2">

                <legend class="legend2">Add Bid Type</legend>

                <div class="form_fields">

                <p>
                <label for="subject" class="label2">Bid Type:</label>
                <input type="input" id="type" name="type" class="textfield2" />
                </p>

                <p>
                <label for="subject" class="label2">Bid Type Code:</label>
                <input type="input" id="code" name="code" class="textfield2" />
                </p>


                <p>
                <label for="description" class="label2">Bid Type Description:</label>
                <textarea id="description" name="description" class="textarea2"></textarea>
                </p>




                <p>
                <label for="userfile" class="label2">Icon:</label>
                <input type="file" id="userfile" name="userfile" class="input_file"  />
                </p>


                </div>

            </fieldset>

            <fieldset class="none">
            <p>
                <input type="submit" id="btnsubmit" name="btnsubmit" class="btn" value="Add" />
    <input type="reset" id="btnreset" name="btnreset" class="btn" value="Reset" />
            </p>
            </fieldset>
        </form>`

以下是控制器代码:

function create() {

        $data = '';


        echo '<pre>';
        echo 'below is Post Fields Data:<br>';  
        print_r($this->input->post());
        echo '<br>Post Fields Data Ends: ';     

    echo '</pre>';



        $this->form_validation->set_rules('type', 'Bid Type', 'trim|required|xss_clean');
        $this->form_validation->set_rules('code', 'Bid Type Code', 'trim|xss_clean');

        $this->form_validation->set_rules('description', 'Bid Type description', 'trim|xss_clean');

        $data['errors'] = array();

        if ($this->form_validation->run()) {
                $data = array(
                    'code'          => $this->form_validation->set_value('code'),
                    'type'          => $this->form_validation->set_value('type'),
                    'description'   => $this->form_validation->set_value('description'),

                );

                if (!is_null($this->bid_types->create_bid_type($data))){
                        $data['errors']['success'] = 'Record Successfully Added!';


                } else {

                    $errors = $this->bid_types->get_error_message();
                    foreach ($errors as $k => $v)   $data['errors'][$k] = $this->lang->line($v);

                }       

        $config['upload_path'] = base_url().'resource/images/uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        //$config['max_size']   = '100';
        //$config['max_width']  = '1024';
        //$config['max_height']  = '768';

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload())
    {
        $data['errors']['upload'] = 'Not Uploaded';
        //$data['errors']['upload'] = $this->upload->display_errors();
        //$error = array('error' => $this->upload->display_errors());

        //$this->load->view('upload_form', $error);
    }
    else
    {
        $data['errors']['upload'] = 'Yes Uploaded';
        //$data['errors']['upload'] = $this->upload->data();
        //$data = array('upload_data' => $this->upload->data());

        //$this->load->view('upload_success', $data);
    }

    echo '<pre>';           
        print_r($this->upload->data());

    echo '</pre>';

        } /* END OF FORM VALIDATRION RUN */

        if(!$this->input->is_ajax_request() && !$this->input->get_post('is_ajax'))
        {   
            $this->load->view('bend/bid_type/create', $data);

        }                               


} /* END OF FUNCTION CREATE */ 

有人可以指导我做错的地方和地点,以及如何将其重新归档。

5 个答案:

答案 0 :(得分:1)

文件数据显示在$ _FILE中,不在$ _POST中。

我认为这一行是你的问题:

$config['upload_path'] = base_url().'resource/images/uploads/';

$config['upload_path']应指向文件系统路径,而不是URL。 尝试更像:

$config['upload_path'] = realpath(APPPATH . '../resource/images/uploads/');

将从您的application文件夹开始,向上一个文件夹,然后进入resource/images/uploads 如果它在其他地方相应地改变它。

P.S。另请检查您的写入权限。

答案 1 :(得分:0)

$this->output->enable_profiler(TRUE)放在create()函数的第一行,它会向您显示调试代码的非常有用的信息$_POST global,如

答案 2 :(得分:0)

Charles表示来自表单提交的请求确实包含帖子数据。

Charles Output

在可以擦除POST数据的create()函数之前是否还有其他事情发生?

答案 3 :(得分:0)

我会根据the user manual中的说明使用action向表单添加echo form_open('/phpdemo/b1/admin/bid_type/create')属性。

答案 4 :(得分:0)

你不能使用

$this->form_validation->set_rules('code', 'Bid Type Code', 'trim|xss_clean');

在multipart中,因此您必须创建自己的验证功能并使用callbacks