Welcome Guest, Not a member yet? Register   Sign In
a form that handles both image upload and text input
#1

[eluser]Unknown[/eluser]
Maybe I'm missing something, but there seems no way of coding a CI form that has both text input fields and a file upload input field.

Seems simple enough.

I have a CI form with validation, it has input fields for article title, description etc. I want to add an image upload field to this form.

However the only examples/tutorials I can find have forms that only have an upload image field or forms that only have text,textarea etc type input fields.

So there needs to be two forms with separate controllers, views and even model I guess.

Is this right?
#2

[eluser]defectivereject[/eluser]
[quote author="kiwiPrometheus" date="1277429308"]Maybe I'm missing something, but there seems no way of coding a CI form that has both text input fields and a file upload input field.

Seems simple enough.

I have a CI form with validation, it has input fields for article title, description etc. I want to add an image upload field to this form.

However the only examples/tutorials I can find have forms that only have an upload image field or forms that only have text,textarea etc type input fields.

So there needs to be two forms with separate controllers, views and even model I guess.

Is this right?[/quote]

You just need to open a multipartform
Code:
echo form_open_multipart('controller/function');
then you can use both upload and inputs in the same form.
Code:
echo "<br /> \n";
echo form_label('First Name*','firstname');
echo form_input('firstname');
echo "<br /> \n";

echo form_label('Surname*','lastname');
echo form_input('lastname');
echo "<br /> \n";

echo form_label('File Location','userfile');
echo "&lt;input type='file' name='userfile' id='picture' /&gt;";
echo "<br /> \n";

I'm extremely new to this but this is a part of a form i have, and how i handle it.
I believe the NAME of your upload has to be userfile though.

then in your controller just validate the upload and if that validates, validate your inputs and if they validate, then insert the data




Theme © iAndrew 2016 - Forum software by © MyBB