Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible with upload a file AND submit text in a single form?

I'm writing a plugin for wordpress where certain information like a name and e-mailaddress and some info is stored in an SQL database table. I've got that working perfectly. But this information also needs a picture to go with it.

So when wordpress admin fills in the form, has the file selected and clicks submit I want the file to be uploaded into a directory and its location stored in a database along with the name and e-mailaddress.

All this preferably needs to be done in just one form.

Is this possible? Or is there another way that would make the end user click only once on a sumbit button.

like image 862
Jesper Avatar asked Nov 16 '11 18:11

Jesper


People also ask

Can you upload documents to forms?

Within your form: Click Add new. Click the drop down menu for additional options (if file upload is not shown) Click on file upload.

What is a file upload form?

File Upload formsAllow users to upload files with their results. Accept any file type. Optionally limit the size of file you want. Give your visitors the ability to submit pictures, documents, or videos using the file upload feature.


2 Answers

Yes, it's possible. Just make sure you set the form enctype="multipart/form-data" and that you use type="file" for file input and regular inputs (type="text", etc) for texts.

You'll need to write a code to move uploaded files to a location you want, as well as to add its info to the database.

See these two nice tutorials: here and here.

like image 151
Shomz Avatar answered Sep 28 '22 20:09

Shomz


Yes, it should be possible.

Just ensure that your <form> has the attributes enctype="multipart/form-data" and method="post"

By PHP side after submit, you can use $_POST variables as usual, plus $_FILES for handling uploads with <input type="file"> in the same form.

See this PHP manual page for details on file upload.

like image 26
Frosty Z Avatar answered Sep 28 '22 19:09

Frosty Z