• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form help needed...........please!! :-)

#1
[eluser]adammorland[/eluser]
I need some help. I have a simple form and I am having trouble creating the controller to make it work. Basically I need the form to do the following:

- Insert three text fields (title, svcheader, svccontent) into my database (table name - 'DBservices')
- upload up to 3 images into an uploads folder - resize the width to 350px - and then insert the filename into the database (image1, image2, image3)
- redirect to my 'success' view.

I'm sure this has probably been answered a million times in here, but I'm really struggling to piece it all together.
Any help would be greatly appreciated as I'm pulling my hair out.

Many thanks.

#2
[eluser]jedd[/eluser]
Hi adammorland and welcome to the CI forums.

Really .. with the scope of things you're trying to do on your first day - forms prep, uploads, form validation - this is a big question to be putting out there. I think your best bet is to go through the tutorials - there are many AV ones you can watch - and many of them tend to cover uploads and forms (unsurprisingly).

If you want specific help with some particular aspect, you'll do better to share your code with us - it's much easier to work from something solid like that, than from nothing. Even if, especially if, you look like you're heading down the wrong track, it means we can point you in the right direction faster.

#3
[eluser]adammorland[/eluser]
Thanks for your quick reply. Here is my form view:

Code:
<?php
        
        $attributes = array('class' => 'addservice', 'id' => 'addservice');
        echo form_open_multipart('cms/services/insert', $attributes);

        //--------------------------------------------
            
        $attributes = array(
            'class' => 'cms_labels',
        );
        echo form_label('Title', 'title', $attributes);
        
        $data = array(
            'name'        => 'title',
            'id'          => 'title',
            'class'       => 'cms_textfield',
        );
        echo form_input($data);
        
        echo "<br />";
        echo "<br />";
        
        //--------------------------------------------
        
        $attributes = array(
            'class' => 'cms_labels',
        );
        echo form_label('Header', 'svcheader', $attributes);
        
        $data = array(
            'name'        => 'svcheader',
            'id'          => 'svcheader',
            'class'       => 'cms_textarea',
            'value'       => '<h1>&nbsp;</h1>',
        );
        echo form_textarea($data);
        
        echo "<br />";
        echo "<br />";

        
        //--------------------------------------------
        
        $attributes = array(
            'class' => 'cms_labels',
        );
        echo form_label('Main Text', 'svccontent', $attributes);
        
        $data = array(
            'name'        => 'svccontent',
            'id'          => 'svccontent',
            'class'       => 'cms_textarea',
        );
        echo form_textarea($data);        
        
        echo "<br />";
        echo "<br />";
        
        //--------------------------------------------
            
        echo "Images:<br /><br />";    
        
        $attributes = array(
            'class' => 'cms_labels',
        );
        echo form_label('Image 1', 'image1', $attributes);
        echo "<span id=\"cms_fileupload\">";
        $data = array(
            'name'        => 'image1',
            'id'          => 'image1',
            'class'       => 'cms_fileupload',
        );
        echo form_upload($data);
        echo "</span>";
        echo "<br />";


        $attributes = array(
            'class' => 'cms_labels',
        );
        echo form_label('Image 2', 'image1', $attributes);
        echo "<span id=\"cms_fileupload\">";
        $data = array(
            'name'        => 'image2',
            'id'          => 'image2',
            'class'       => 'cms_fileupload',
        );
        echo form_upload($data);
        echo "</span>";
        echo "<br />";


        $attributes = array(
            'class' => 'cms_labels',
        );
        echo form_label('Image 3', 'image1', $attributes);
        echo "<span id=\"cms_fileupload\">";
        $data = array(
            'name'        => 'image3',
            'id'          => 'image3',
            'class'       => 'cms_fileupload',
        );
        echo form_upload($data);
        echo "</span>";
        echo "<br />";

        
        //--------------------------------------------

        echo "<br />";
        $attributes = array(
            'name'        => 'reset',
            'class'       => 'cms_submitbutton',
        );
        echo form_reset($attributes, 'Cancel');
        
        $attributes = array(
            'class'       => 'cms_submitbutton',
        );
        echo form_submit($attributes, 'Save');
        
        //--------------------------------------------
        
        
        
        echo form_close();
        ?&gt;



Here is what I have to insert the text fields in the DB:
Code:
function insert()
        {    
              $this->db->insert('DBservices', $_POST);
              redirect('cms/success');
        }


Where i'm getting stuck is the multiple file upload. It will always be up to a max of three images. 'image1', 'image2', 'image3',
I've tried the various multiple file uploads solutions in the forum but I just can't any of them to work.

I hope this is enough for someone to step in an point me in the right direction!!

#4
[eluser]bretticus[/eluser]
If you are looking for the file names, they probably won't be in your post array. Try this to see...

Code:
function insert()
        {    
              //$this->db->insert('DBservices', $_POST);
              //redirect('cms/success');
              print_r($_POST);
              print_r($_FILES);
        }

...then again, perhaps i completely misunderstood you.

#5
[eluser]adammorland[/eluser]
that is only part of it.

I want to upload the images, resize them and then get the file names to add into the database.

#6
[eluser]jedd[/eluser]
[quote author="adammorland" date="1251861220"]
I want to upload the images, resize them and then get the file names to add into the database.
[/quote]

What happens if two or more files have the same name?

#7
[eluser]adammorland[/eluser]
could I not use the 'encrypt_name' preference?

#8
[eluser]jedd[/eluser]
Edit: Ahh .. not the encryption class, but the crypt option on the upload class - cool - I take it all back. Wink

So I'm guessing you've already got space for that in your schema?

#9
[eluser]adammorland[/eluser]
yes


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.