Когда эта форма обрабатывается, генерируется 2 запроса.
В запросе 1: все данные успешны, но за исключением рисунка. картинка: звучит «НУЛЬ».
запрос 2: картинка написана правильно. но другие данные пишутся «NULL».
Я хочу, чтобы вместо запроса 2 данные изображения в запросе 2 приходили на запрос 1, и должен быть сформирован только 1 запрос.
Это мой контроллер и модель
public function send_Basvur_message(){
$this->load->library("form_validation");
$this->load->model("Basvur_model");
$this->form_validation->set_rules("name", "Ad", "trim|required");
$this->form_validation->set_rules("email", "E-posta", "trim|required|valid_email");
$this->form_validation->set_rules("subject", "Konu", "trim|required");
$this->form_validation->set_rules("message", "Mesaj", "trim|required");
$this->form_validation->set_rules("url", "url");
$this->form_validation->set_rules("captcha", "Doğrulama Kodu", "trim|required");
$path = './panel/uploads/basvur_v/';
$initialize = $this->upload->initialize(array(
"upload_path" => $path,
"allowed_types" => "gif|jpg|jpeg|png|bmp",
"remove_spaces" => TRUE
));
$imagename = 'no-img.jpg';
$config['max_size'] = 51200;
$config['overwrite'] = false;
$config['encrypt_name'] = false;
$config['remove_space'] = false;
$imagename = 'no-img.jpg';
if($this->form_validation->run() === FALSE){
} else if(!$this->upload->do_upload('img_url')) {
$this->session->set_flashdata('info','Action Completed');
redirect(base_url("basvuru"));
} else {
$insert = $this->Basvur_model->add(
array(
"name" => $this->input->post("name"),
"email" => $this->input->post("email"),
"message" => $this->input->post("message"),
"subject" => $this->input->post("subject"),
"url" => $imagename,
"created_at" => date("Y-m-d H:i:s")
)
);
$data = $this->upload->data();
$imagename = $data['file_name'];
$this->Basvur_model->setURL($imagename);
$this->Basvur_model->create();
$this->session->set_flashdata('img_uploaded', $imagename);
if($this->session->userdata("captcha") == $this->input->post("captcha")){
$name = $this->input->post("name");
$email = $this->input->post("email");
$subject = $this->input->post("subject");
$message = $this->input->post("message");
$email_message = "{$name} isimli ziyaretçi. Başvuru Yaptı <br><b>Mesaj : </b> {$message} <br> <b>E-posta : </b> {$email}";
if(send_email("", "Yeni Aday başvurusu | $subject", $email_message)){
$this->session->set_flashdata('success','Action Completed');
redirect(base_url("basvuru"));
// TODO Alert..
} else {
$this->session->set_flashdata('success','Action Completed');
redirect(base_url("basvuru"));
// TODO Alert..
}
} else {
//başarısıs
$this->session->set_flashdata('error','Action Not Completed');
redirect(base_url("basvuru"));
}
}
}
Модель
<?php
class Basvur_model extends CI_Model
{
public $tableName = "basvurs";
public function __construct()
{
parent::__construct();
}
private $_ID;
private $_url;
public function setID($ID) {
$this->_ID = $ID;
}
public function setURL($url) {
$this->_url = $url;
}
// get image
public function getPicture() {
$this->db->select(array('p.id', 'p.url'));
$this->db->from('basvurs p');
$this->db->where('p.id', $this->_ID);
$query = $this->db->get();
return $query->row_array();
}
// insert image
public function create() {
$data = array(
'url' => $this->_url,
);
$this->db->insert('basvurs', $data);
return $this->db->insert_id();
}
public function get($where = array())
{
return $this->db->where($where)->get($this->tableName)->row();
}
/** Tüm Kayıtları bana getirecek olan metot.. */
public function get_all($where = array(), $order = "id ASC")
{
return $this->db->where($where)->order_by($order)->get($this->tableName)->result();
}
public function add($data = array())
{
return $this->db->insert($this->tableName, $data);
}
public function update($where = array(), $data = array())
{
return $this->db->where($where)->update($this->tableName, $data);
}
public function delete($where = array())
{
return $this->db->where($where)->delete($this->tableName);
}
}