booxvid Posted October 9, 2012 Share Posted October 9, 2012 (edited) I was trying to make form wherein you give you a title and its description plus, you can upload photo with it. The problem is.. I had the difficulty in saving together the texts and also the photo my text and photo details are saved into one database table which is named, "texts" here's my controller: function addpost(){ /*ID IS THE BLOG PAGE ID*/ $id = $this->uri->segment(3); $username = $this->session->userdata('username'); $userid = $this->blog_model->get_id('username',$username); $this->form_validation->set_rules('blogtitle','Blog Title','is_unique[texts.text_title]'); $this->form_validation->set_rules('desc','Description','required'); $this->form_validation->set_error_delimiters(' ',''); if($this->form_validation->run()==FALSE){ echo ""; $this->view_posts(); } else{ $title =$this->input->post('blogtitle'); $desc = $this->input->post('desc'); $timezone = "Asia/Manila"; date_default_timezone_set ($timezone); $date = date("Y-m-d"); $timetoday = date("H:i:s"); $photo = $this->input->post('upload'); if ($photo) { /*UPLOAD IT AND SAVE IT TO THE PROFILE FOLDER AND ITS THUMBNAIL AS WELL*/ $data_second=$this->blog_model->do_uploadthispost($userid); print_r($data_second); } $data = array( 'text_title'=>$title, 'text_content'=>$desc, 'text_date'=>$date, 'text_time'=>$timetoday, 'text_user_id'=>$userid, 'text_blogpage_id'=>$id ); $userdata = array( 'username' => $username, 'logged_in' => TRUE, 'user_id' => $userid ); $new_data = $data + $data_second; $this->blog_model->create_new($newdata,'texts'); /*GIVES A PROMPT MESSAGE THAT YOU SUCCESSFULLY CREATED A BLOG*/ echo ""; $this->view_posts(); } } and here's the model: in my model i have these variable inside my construct : $this->photos_path = realpath(APPPATH. '../assets/img/posts/'); $this->photos_path_url = base_url().'assets/img/posts/'; wherein i have this variables before my construct: var $photos_path; var $photos_path_url; and this is my main function from my blog_model which it will upload the photo hopefully in the requested dir and its thumbnail also: function do_uploadthispost() { $config = array( 'allowed_types' => 'jpg|jpeg|gif|png', 'upload_path' => $this->photos_path, 'max_size' => 10000 ); $this->load->library('upload', $config); $this->upload->do_upload(); $image_data = $this->upload->data(); $config = array( 'source_image' => $image_data['full_path'], 'new_image' => $this->photos_path . '/thumbs', 'maintain_ratio' => true, 'width' => 690, 'height' => 900 ); $this->load->library('image_lib', $config); $this->image_lib->resize(); $filepath = $image_data['file_path']; $filename = $image_data['file_name']; $type = $image_data['file_type']; $size = $image_data['file_size']; $data = array(); /*SAVE IT INTO THE DATABASE*/ if($size<10000){ $data = array( 'filename'=>$filename, 'filepath'=>$filepath, 'type'=>$type, 'size'=>$size, ); //$this->update_this($data,); } return $data; } also: here's the portion where i placed my form: <div id="myModal" class="modal hide fade"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <?php echo heading('Add Post',3); ?> </div> <div class="modal-body"> <hr> <?php $attributes = array('class'=>'form-inline','id'=>'thisForm'); echo form_open_multipart('posts/addpost/'.$idblog.'',$attributes); echo form_label('Title:','title'); $data_input_fname = array( 'class'=>'input-large', 'name'=>'blogtitle', 'id'=>'blogtitle', 'maxlength'=>'100', 'placeholder'=>'Insert you blog title here'); echo nbs(3); echo br(1); echo form_input($data_input_fname); echo br(2); echo form_upload('userfile',array('class'=>'btn btn-primary')); echo br(2); echo form_label('Content:','content'); $data_inputdesc = array( 'type'=>'textarea', 'style'=>'width: 500px; height: 150px', 'class'=>'input-large', 'name'=>'desc', 'id'=>'desc', 'placeholder'=>'Insert text here' ); echo nbs(2); echo form_textarea($data_inputdesc); ?> <br/><br/> <center> <?php $submit_data = array('type'=>'submit', 'class'=>'btn btn-large btn-primary', 'name'=>'submit_form', 'value'=>'Submit!'); echo form_submit($submit_data); echo nbs(5); $reset_data = array('type'=>'reset', 'class'=>'btn btn-large', 'name'=>'reset_form', 'value'=>'Reset!'); echo form_reset($reset_data); echo form_close(); ?></center> </div><!---modal body --> </div> Edited October 9, 2012 by booxvid Quote Link to comment https://forums.phpfreaks.com/topic/269252-setting-up-a-text-input-and-image-input-in-a-single-form-w-codeigniter/ Share on other sites More sharing options...
Mahngiel Posted October 11, 2012 Share Posted October 11, 2012 I had the difficulty in saving together the texts and also the photomy text and photo details are saved into one database table which is named, "texts" There is too much code to extrapolate what exactly the problem you're encountering is. Quote Link to comment https://forums.phpfreaks.com/topic/269252-setting-up-a-text-input-and-image-input-in-a-single-form-w-codeigniter/#findComment-1384662 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.