[eluser]solid9[/eluser]
okay to make it clear this is the form,
Code:
<?php
echo '<br>';
echo form_open_multipart('main/process_post');
?>
<div id="register" align="center">
<table width="550" bgcolor="#333333">
<tr>
<td align="left">Offering</td>
<td align="left">
<?php
//[swapid] => 14
//[date_posted] => 2012-03-10
//[offering] => eight
//[seeking] => 8
if(!empty($swap->swapid)) {
$offer = $swap->offering;
echo form_hidden('swap_id', $swap->swapid);
} else {
$offer = '';
}
$data_form = array(
'name' => 'offering',
'id' => 'offering',
'value' => $offer,
'rows' => '15',
'cols' => '55',
);
echo form_textarea($data_form);
?>
</td>
</tr>
<tr>
<td align="left">Seeking</td>
<td align="left">
<?php
if(!empty($swap->swapid)) {
$seek = $swap->seeking;
} else {
$seek = '';
}
$data_form = array(
'name' => 'seeking',
'id' => 'seeking',
'value' => $seek,
'rows' => '15',
'cols' => '55',
);
echo form_textarea($data_form);
?>
</td>
</tr>
<tr>
<td align="left"> </td>
<td align="left">
<b>Upload photo(s)</b> <br>
<input type="file" name="userfile1" size="20" /><br>
<input type="file" name="userfile2" size="20" /><br>
<input type="file" name="userfile3" size="20" /><br>
<input type="file" name="userfile4" size="20" /><br>
<input type="file" name="userfile5" size="20" /><br><br>
<?php echo form_submit('mysubmit', 'Publish'); ?></td>
</div>
</table>
<?php
echo form_close();
?>
and this the method
Code:
function process_post() {
//get segment(3)
$swap_id = $this->input->post('swap_id');
$img1 = 'userfile1';
$img2 = 'userfile2';
$img3 = 'userfile3';
$img4 = 'userfile4';
$img5 = 'userfile5';
$file1 = '';
$file2 = '';
$file3 = '';
$file4 = '';
$file5 = '';
//validate data input first
$this->form_validation->set_rules('seeking', 'seeking', 'required');
$this->form_validation->set_rules('offering', 'offering', 'required');
//if validation has an error display form again.
if ($this->form_validation->run() == FALSE)
{
//Refresh the page and display error message
$username = $this->session->userdata('username');
$this->data['header_message'] = 'Please fill-up seeking and offering fields.';
$this->data['header'] = $this->load->view('header', $this->data, TRUE);
$this->data['member_menu'] = $this->load->view('member_menu', null, TRUE);
$this->data['midnav'] = $this->load->view('post_page', $this->data, TRUE);
$this->load->view('front_page', $this->data);
} elseif(empty($swap_id)) {
//Save to swap table, update users_swap table
//This is for new records
$offer = $this->input->post('offering');
$seek = $this->input->post('seeking');
$prodid = $this->bs_model->publish_post($offer, $seek);
//process image upload
$config['upload_path'] = './photo-product/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width'] = '500';
$config['max_height'] = '500';
$this->load->library('upload', $config);
//$this->upload->initialize($config);
$this->upload->do_upload($img1);
$img1 = $this->upload->data($img1);
//if(isset($userfile1)) {
$file1 = $img1['file_name'];
$this->upload->do_upload($img2);
$img2 = $this->upload->data($img2);
$file2 = $img2['file_name'];
$this->upload->do_upload($img3);
$img3 = $this->upload->data($img3);
$file3 = $img3['file_name'];
$this->upload->do_upload($img4);
$img4 = $this->upload->data($img4);
$file4 = $img4['file_name'];
$this->upload->do_upload($img5);
$img5 = $this->upload->data($img5);
$file5 = $img5['file_name'];
//}
echo "<pre>";
echo '<br>', $file1;
echo '<br>', $file2;
echo '<br>', $file3;
echo '<br>', $file4;
echo '<br>', $file5;
echo "</pre>";
//save filename to sphoto table
//$this->bs_model->save_product_photo($prodid, $file1, $file2, $file3, $file4, $file5);
//display view page
$username = $this->session->userdata('username');
$this->data['header_message'] = 'Your post is successfully published!';
$this->data['header'] = $this->load->view('header', $this->data, TRUE);
$this->data['member_menu'] = $this->load->view('member_menu', null, TRUE);
$this->data['midnav'] = $this->load->view('post_page', $this->data, TRUE);
$this->load->view('front_page', $this->data);
} elseif(!empty($swap_id)) {
//update table
//This is for existing record for updating
$offer = $this->input->post('offering');
$seek = $this->input->post('seeking');
$this->bs_model->update_post($swap_id, $offer, $seek);
$this->data['header_message'] = 'Your post is successfully updated!';
$this->data['header'] = $this->load->view('header', $this->data, TRUE);
$this->data['member_menu'] = $this->load->view('member_menu', null, TRUE);
$this->data['midnav'] = $this->load->view('post_page', $this->data, TRUE);
$this->load->view('front_page', $this->data);
}
}
thanks in advanced.