Can I force a form's action without a 'submit'?

Let’s say I have two forms on the same page. The first form is for input of text data and the second for is for uploading an image.

  1. I want the first form to record the input from the input fields to a mySQL table BEORE the action of the second form takes place.

  2. Then I want to upload the image file (which has already been selected by the “Browse” button) without the user having to click on an “upload image” button. I need to force the “action” somehow after the action of the first form is complete.

Here are the 2 forms, each with different actions:


<form action="addItem.php" method="post">
	<p>Item id: <input type="text" name="item_num" size="15" maxlength="20" value="<?php if (isset($_POST['item_num'])) echo $_POST['item_num']; ?>" /></p>
	<p>Item Name: <input type="text" name="item_name" size="15" maxlength="40" value="<?php if (isset($_POST['item_name'])) echo $_POST['item_name']; ?>" /></p>
	<p>Item Type: <input type="text" name="item_cat" size="20" maxlength="80" value="<?php if (isset($_POST['item_cat'])) echo $_POST['item_cat']; ?>"  /> </p>
	
	<p>Item Description:<br/><textarea name="item_desc" id="textarea" cols="35" rows="5"></textarea>
	
		
	<p>Item Price: <input type="text" name="item_price" size="20" maxlength="80" value="<?php if (isset($_POST['item_price'])) echo $_POST['item_price']; ?>"  /> </p>
    <br />
    <br />
    <label>
    <input name="onweb" type="checkbox" checked ="checked" />
    show this item on the website</label>
    <br />
  </p>
	<input type="hidden" name="submitted" value="TRUE" />
	<p><input type="submit" name="submit" value="Post Item" /></p>
	<input type="hidden" name="submitted" value="TRUE" />
</form>


<form action="processImage.php" enctype="multipart/form-data" method="post">
<tr>
    <td valign=top><strong>Image file:</strong></td>
    <td><input name="upfile" type="file" size="30"><br>
        Image files must be in JPEG, GIF, or PNG format.
    </td>
</tr>

<tr>
    <td colspan="2"><br/>
	<input type="submit" value="Upload Image">
    </td>
</tr>
</form>

I hope this is stated clearly. Thanks again for any assistance.

Chop

No, you cannot do this with HTML or XHTML. They are markup languages whose only purpose is to indicate the semantic meaning of the content.

You could achieve something like this with ajax, but that question belongs in the JavaScript forum.

I may be missing the point, but I don’t see any reason to use two forms. Submit everything, and process in any order you prefer.

cheers,

gary

The only reason why you’d use two forms is if the they can de used independently - some people use form one and others use form two and some use one and then come back to use the other.

I agree with you that for what the OP is trying to do there should only be one form.

I couldn’t guess your intention in making two forms. Capture the first part even if the second part didn’t work?
The page below will be helpful:

How to create a multi-submit form

I guess my thinking was that using a form that begins with:
form action=“processImage.php” enctype=“multipart/form-data” method=“post”>

it was only for uploading an image. Are you saying I can add any other input fields that I want? (still new to forms)

I’m using php with the form to upload some text information into a database table then, once the data has been added, retrieve the unique primary key number from that record so that I can append it onto the front of the image name that will be uploaded in order to make sure the image name itself is unique. For instance:

myImage.jpg ----> 102myImage.jpg

where the 102 is the same as the primary key for that record.

Therefore I need the text data uploaded before the actual image is uploaded to have time to retrieve the unique number. However, I still wanted the user to be able to browse to the image that will be uploaded on the same form as all the other input.

…hope this makes sense. There are better ways maybe, so any suggestions are welcome.

thanks

multipart/form-data means that the form consists of multiple parts. One part will be the file being updated via the <input type=“file”> and the other part will be all the other fields input into the form.

Thanks Felgall. I put everything into one form, shuffled things around for about an hour, sprinkled a little php here and there and … voila, seems to be doing about what I wanted it to do. A little more fine tuning and I’ll be ready for evening cocktails.

chop

Steve, rather