CodeIgniter Forums
upload image in a form - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: upload image in a form (/thread-53610.html)



upload image in a form - El Forum - 07-31-2012

[eluser]santorini[/eluser]
hello,
is it possible to upload a picture (form_open_multipart), within an 'normal' input-form, including different values(date,name, email etc.).
?
All entries should be sent with only one submit button.

My picture upload works only with an additional submit-button.


Code:
//view

echo form_open() . PHP_EOL;
    echo form_fieldset() . PHP_EOL;
    echo form_error('datum') ? '<div ' . $fehler . '>' . PHP_EOL : '<div>' . PHP_EOL;
    echo form_label('Datum:*', 'datum') . PHP_EOL;
    $data = array(
        'name'        => 'datum',
        'id'          => 'datepicker',
        'class'       => 'kurz',
    );
    echo form_input($data, set_value('datum', $datum)) . PHP_EOL;
    echo '</div>';
    echo form_label('Bild hochladen:', 'bild') . PHP_EOL;
    echo form_open_multipart('redaktion/agenda/doUpload');
    echo form_upload('userfile');
    echo form_fieldset_close() . PHP_EOL;
    echo form_fieldset() . PHP_EOL;
    echo form_button('abbrechen', 'zurück', 'onClick=self.location.href="' . $back_link . '"') PHP_EOL;
    echo form_submit('submit', $submit_text, 'class="mittel"') . PHP_EOL;
    echo form_fieldset_close() . PHP_EOL;
    echo form_close() . PHP_EOL;?&gt;

&lt;!--image upload additional --&gt;
    &lt;?php
    echo form_open_multipart('redaktion/agenda/doUpload');
    echo form_upload('userfile');
    echo form_submit('submit', 'Upload');
    echo form_close();
    ?&gt;

thanks for helping me :-)



upload image in a form - El Forum - 07-31-2012

[eluser]CroNiX[/eluser]
That should all be part of a single, multipart form with only 1 open and 1 close form tag, and a single submit just before the form_close().

Also, in one of your forms you are sending the POST data to 'redaktion/agenda/doUpload' and the other is being sent to the current URL, whatever that is. Don't know if it makes a difference for you.

Try:
Code:
echo form_open_multipart('redaktion/agenda/doUpload') . PHP_EOL;
echo form_fieldset() . PHP_EOL;
echo form_error('datum') ? '<div ' . $fehler . '>' . PHP_EOL : '<div>' . PHP_EOL;
echo form_label('Datum:*', 'datum') . PHP_EOL;
$data = array(
    'name'        => 'datum',
    'id'          => 'datepicker',
    'class'       => 'kurz',
);
echo form_input($data, set_value('datum', $datum)) . PHP_EOL;
echo '</div>';
echo form_label('Bild hochladen:', 'bild') . PHP_EOL;
echo form_fieldset_close() . PHP_EOL;
echo form_fieldset() . PHP_EOL;
echo form_button('abbrechen', 'zurück', 'onClick=self.location.href="' . $back_link . '"') PHP_EOL;
echo form_upload('userfile');
echo form_submit('submit', $submit_text, 'class="mittel"') . PHP_EOL;
echo form_fieldset_close() . PHP_EOL;
echo form_close() . PHP_EOL;?&gt;



upload image in a form - El Forum - 07-31-2012

[eluser]santorini[/eluser]
Thank you very much..You've helped me a lot! Now i'm able to send the image file and the other form datas to a controller for for further processing. The form datas are stored in the db and displayed in a view. The image file is saved in the correct folder. Now I have to show the image on the same view.. Hope it will work :-)

Thanks again
cheers
santorini