2016-12-17 1 views
1

입력 유형 파일 및 기타 양식 필드를 포함하는 간단한 양식이 있습니다. 내가 입력 형식 파일 데이터를 컨트롤러에 보낼 수 있지만 입력 형식 파일과 함께 다른 양식 데이터를 보내는 문제가 있습니다.
양식 - -codeIgniter에서 ajax를 사용하여 입력 데이터와 함께 양식 데이터 보내기

<form method="post" id="theme_option_form" enctype="multipart-formdata"> 
     Logo :<input type="file" name="image_file" id="image_file"> 
     Logo Size :<input type="text" id="logo_size" class="form-control input-sm"> 
     Heading Size :<input type="text" id="hding_size" class="form-control input-sm"> 
     <input type="submit" name="upload" id="upload" value="Upload" class="btn btn-primary btn-sm"> 
</form> 

아약스 코드 -

$('#theme_option_form').on("submit",function(e){ 
    var hding_size=$('#hding_size').val(); 
    var logo_size=$('#logo_size').val(); 
       $.ajax({ 
        url:base_url+'admin/theme_options_data', 
        method:'post', 
        data:new FormData(this), 
        contentType:false, 
        cache:false, 
        processData:false, 
        success:function(data){ 
         alert(data); 
        } 
       });   
}); 

컨트롤러 기능 -

public function theme_options_data() 
{ 
     if(isset($_FILES['image_file']['name'])) 
     { 
      $this->load->helper('string'); 
      $logo_name=random_string('alnum',5); 
      $config['upload_path']='./upload'; 
      $config['allowed_types']='jpg|jpeg|png|gif'; 
      $config['file_name']=$logo_name; 
      $this->load->library('upload',$config); 
      if(!$this->upload->do_upload('image_file')) 
      { 
       echo $this->upload->display_errors(); 
      } 
      else 
      { 
       $data=$this->upload->data(); 
      } 
      } 

    } 

파일 업로드가 제대로 작동을하지만
여기 내가 지금까지 한 일이다 단지 폼 데이터 (로고 크기, 제목 크기 등)를 컨트롤러에 보내고 나중에 모든 데이터를 데이터베이스에 저장해야합니다.
도와주세요.
감사합니다.

+0

$ _POST를 사용하는 값을 [ 'logo_size'] 얻을 수 있지만, 당신이 당신의 입력에 이름 = "logo_size"를 둘 필요는 Shailesh 감사에 대한 @ – webDev

답변

0

양식 ... 입력란의 이름을 입력하십시오.

<form method="post" id="theme_option_form" enctype="multipart-formdata"> 
    Logo :<input type="file" name="image_file" id="image_file"> 
    Logo Size :<input type="text" name="logo_size" id="logo_size" class="form-control input-sm"> 
    Heading Size :<input type="text" name="hding_size" id="hding_size" class="form-control input-sm"> 
    <input type="submit" name="upload" id="upload" value="Upload" class="btn btn-primary btn-sm"> 

컨트롤러

public function theme_options_data() 
{ 
     if(isset($_FILES['image_file']['name'])) 
     { 
      $this->load->helper('string'); 
      $logo_name=random_string('alnum',5); 
      $config['upload_path']='./upload'; 
      $config['allowed_types']='jpg|jpeg|png|gif'; 
      $config['file_name']=$logo_name; 
      $this->load->library('upload',$config); 
      if(!$this->upload->do_upload('image_file')) 
      { 
       echo $this->upload->display_errors(); 
      } 
      else 
      { 
       $data=$this->upload->data(); 
      } 
      } 
     $logo_size = $_POST['logo_size']; 
     $heading_size = $_POST['hding_size']; 
    } 
+0

을 제기 도움이, 그것은 작동하지만 난 font_selector 드롭 다운에서 글꼴을 선택할 수 있습니다. div를 사용하여이를 만들었으므로 어떻게 가치가 있습니까? – Deepak

관련 문제