[eluser]loopymonkey[/eluser]
ok I feel I'm close. I'm trying to combine
Yannicks excellent form tutorial for codeigniter with codeigniter's
uploader helper tutorial. I just want a simple form that uploads to a directory and passes along the data to my database including JUST the name of the file that was uploaded. Right now everything's working except the image uploading. The data I'm trying to collect is name, email, comments and the image file name as well as uploading the file.
My form is made up of 1. model for the database, 2. form controller, 3. form view. I am calling all my upload $config data from the config folder after making my own Upload.php file with all my settings. I know this works i've successfully used the upload tutorial in the user guide and was able to upload an image with that trick.
Any leads or help is much appreciated:
MODEL:
Code:
<?php
class Form_model extends Model
{
function Form_model()
{
parent::Model();
}
function add_participant()
{
$YourName = $this->input->post('YourName');
$email = $this->input->post('email');
$comments = $this->input->post('comments');
$userfile = $this->input->post('userfile');
$this->db->query("INSERT INTO participants (id, YourName, email, comments, userfile) VALUES(NULL, '$YourName', '$email', '$comments', '$userfile')");
}
function list_participants()
{
$query = $this->db->query("SELECT * FROM participants");
return $query;
}
}
?>
FORM VIEW:
Code:
<div class="formArea">
<div class="errors"><?php echo $this->validation->error_string; ?></div>
<?php echo form_open_multipart('form/index'); ?>
<p class="formBold"><label for="YourName">YOUR NAME</label></span><br>
<?php echo form_input($YourName); ?>
<p class="formBold"><label for="email">YOUR EMAIL ADDRESS</label></span><br>
<?php echo form_input($email); ?>
<p class="formBold"><label for="comments">COMMENTS</label></span><br>
<?php echo form_textarea($comments); ?>
<p class="formBold"><label for="userfile">UPLOAD YOUR PHOTO</label></span><br>
<?php echo form_upload($userfile); ?>
<?php echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>
FORM CONTROLLER:
Code:
<?php
class Form extends Controller {
function index()
{
parent::Controller();
# loaders
$this->load->library('validation');
$this->load->library('email');
$this->load->helper(array('form', 'url', 'array'));
$this->load->library('upload');
$rules['YourName'] = "required";
$rules['email'] = "required|valid_email";
//$rules['image'] = "required";
$this->validation->set_rules($rules);
#Input and textarea field attributes
$data['YourName'] = array('name' => 'YourName', 'id' => 'YourName');
$data['email'] = array('name' => 'email', 'id' => 'email');
$data['comments'] = array('name' => 'comments', 'id' => 'comments', 'rows' => 3, 'cols' => 48);
$data['userfile'] = array('name' => 'userfile', 'id' => 'image');
//$data = array('upload_data' => $this->upload->data());
if ($this->validation->run() == FALSE)
{
$this->load->view('form_view', $data);
}
else
{
$YourName = $this->input->post('YourName');
$email = $this->input->post('email');
$comments = $this->input->post('comments');
$userfile = $this->input->post('userfile');
$this->load->view('formsuccess');
$this->load->model('Form_model','', TRUE);
$this->Form_model->add_participant();
}
}
function results()
{
$this->load->helper(array('form', 'url', 'array'));
$this->load->model('Form_model', '', TRUE);
$data['query'] = $this->Form_model->list_participants();
$this->load->view('results', $data);
}
}
?>