0

I am now creating a simple mail system.In that I have a mail compose section in which I have 3 textfields and a fileupload.I want to insert the data entered in the textarea and also the choosen image.But I am not able to insert the data. Please help me

My controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Dashboard_controller extends CI_Controller {

    public function composepageview()
    {
        $this->load->view('mail_compose');
    }

    public function emailcompose()
    {


        $config['upload_path']          = './uploads/';
        $config['allowed_types']        = 'gif|jpg|png|pdf|doc';
        $this->load->library('upload', $config);

                if ($this->upload->do_upload())
                {
                   $data = $this->input->post();
                   $image = $this->upload->data();
                   $to= $this->input->post('to');
                   $subject= $this->input->post('subject');
                   $content= $this->input->post('content');
                   $file=base_url("uploads/".$image['raw_name'].$image['file_ext']);
                   $data['filepath']=$file;
                   $data=array(
                      "to"=>$to,
                      "subject"=>$subject,
                      "content"=>$content,
                      "filepath"=>$data['filepath']
                     );
                      $this->Login_model->compose($data);

                }
                else
                {
                     echo "fail";
                }
    }       
}
?>

My model

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Login_model extends CI_Model {

//Composing mail    
    public function compose($data)
    {
         $this->db->insert('compose', $data);
    }

}   

my view

                <div class="compose-mail">
                        <form role="form-horizontal" method="post" action="<?php echo base_url();?>index.php/Dashboard_controller/emailcompose">
                            <div class="form-group">
                                <label for="to" class="">To:</label>
                                <input type="text"  name="to" class="form-control">


                            </div>

                            <div class="form-group">
                                <label for="subject" class="">Subject:</label>
                                <input type="text" name="subject" class="form-control">
                            </div>

                            <div class="compose-editor">
                                <textarea class="wysihtml5 form-control" name="content" rows="9"></textarea>

                                <input type="file" name="userfile" class="default">

                            </div>
                            <div class="compose-btn">
                                <button class="btn btn-primary btn-sm"><i class="fa fa-check"></i> Send</button>
                                <button class="btn btn-sm"><i class="fa fa-times"></i> Discard</button>
                            </div>

                        </form>
                    </div>  

1 Answer 1

1

You are missing enctype="multipart/form-data" and have not added button type="submit" in your form.

<div class="compose-mail">
      <form role="form-horizontal" method="post" action="<?php echo base_url();?>index.php/Dashboard_controller/emailcompose" enctype="multipart/form-data">
          <div class="form-group">
              <label for="to" class="">To:</label>
              <input type="text"  name="to" class="form-control">
           </div>

           <div class="form-group">
               <label for="subject" class="">Subject:</label>
               <input type="text" name="subject" class="form-control">
           </div>

           <div class="compose-editor">
                <textarea class="wysihtml5 form-control" name="content" rows="9"></textarea>

                <input type="file" name="userfile" class="default">

            </div>
            <div class="compose-btn">
                 <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> Send</button>
                 <button class="btn btn-sm"><i class="fa fa-times"></i> Discard</button>
            </div>

    </form>
</div>  

Hope this can help you.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help.Now I am able to able insert data and files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.