1

First of all here is my code:

<form id="registration_form" action="AddProductServlet" method="post">
            <div>
            <label>
                    <input placeholder="Product ID" name="pid" type="text">
                </label> 
            </div>
            <div>
                <label>
                    <input placeholder="Product Name" name="pname" type="text">
                </label>
            </div>
            <div>

        <h3> Choose Image to Upload </h3>

        <form action="upload" method="post" enctype="multipart/form-data">

            <input type="file" name="file" />

            <input type="submit" value="Add Product" />

        </form>         
        </div>
        </form>

As I have done here, having a form tag within a form tag is invalid.

Also since it is not possible to invoke the two different actions within the same form tag.

So is there any way I can both upload the image to my local drive and also get the product details and the image name to be stored in the database for later retrieval?

AKronym
  • 63
  • 7
  • Handle the upload in the `AddProductServlet` action, together with the rest of the data. And add `enctype="multipart/form-data"` attribute to your `#registration_form`. – beerwin Jul 26 '16 at 10:24
  • Also, remove the inner form tag, leave just the upload field and the submit button. – beerwin Jul 26 '16 at 10:25

1 Answers1

0

You can handle few input in one form. Try something like:

<form action="upload" method="post" enctype="multipart/form-data">
   <input type="file" name="file" /> <br/>
   Product ID: <input type="text" name="pid"> <br/>
   Product Name: <input type="text" name="pname"> <br/>
   <input type="submit" value="Add Product" />
</form>
Marcon
  • 385
  • 4
  • 11