One submit button for these two different forms?

Discussion in 'Programming' started by stompergames, Aug 18, 2008.

  1. #1
    Is it possible for me to have one submit button for these two different forms, or possible merge the two forms into one? (the enctype attribute on the second form messes with the select option if I merge the two)

    echo 'Product '.$model.' submitted successfully!<br /><br />
    Select Maker from the list and Submit the Product Picture 
    (picture must have same name as the model name)
    <br />
    //FIRST FORM
    <form action="uploader.php" method="POST">
    <select name="modelmaker">
    	<option>Select</option>
    	<option>Hanns-G</option>
    	<option>Acer</option>
    	<option>HP</option>
    	<option>Samsung</option>
    	<option>Viewsonic</option>
    	<option>BenQ</option>
    	<option>Dell</option>
    	<option>Westinghouse</option>
    	<option>LG</option>
    	<option>Sony</option>		
    </select></form>
    
    //SECOND FORM
    <form enctype="multipart/form-data" action="uploader.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" value="Upload File" />
    </form>'
    Code (markup):

     
    stompergames, Aug 18, 2008 IP
  2. jack_ss

    jack_ss Guest

    Messages:
    94
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can submit 2 forms at once, if you don't mind opening a new window..
    <form name="form1" ...blah>
    </form>
    <form name="form2"  target="xxx" ...blah>
    </form>
    <input type="button" onclick="document.form1.submit(); document.form12.submit();">
    
    Code (markup):
    However, I don't see any reason why you would need to in your example. You should be able to just do:
    <form action="uploader.php" method="POST">
    <select name="modelmaker">
    	<option>Select</option>
    	<option>Hanns-G</option>
    	<option>Acer</option>
    	<option>HP</option>
    	<option>Samsung</option>
    	<option>Viewsonic</option>
    	<option>BenQ</option>
    	<option>Dell</option>
    	<option>Westinghouse</option>
    	<option>LG</option>
    	<option>Sony</option>		
    </select></form>
    
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" value="Upload File" />
    </form>
    Code (markup):
     
    jack_ss, Aug 18, 2008 IP
  3. stompergames

    stompergames Peon

    Messages:
    222
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    why would there need to be a target?
     
    stompergames, Aug 18, 2008 IP
  4. jack_ss

    jack_ss Guest

    Messages:
    94
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    So it opens in another window. (note: this is untested).
     
    jack_ss, Aug 19, 2008 IP
  5. eponus

    eponus Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I don't see why the target="_blank" is necessary, try it without and see if it works.
     
    eponus, Aug 27, 2008 IP
  6. jack_ss

    jack_ss Guest

    Messages:
    94
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I am theorizing that the first form will submit and redirect the browser before the second is submitted. Again, untested and entirely theory.
     
    jack_ss, Aug 28, 2008 IP