Can I have two forms on one page?

Hi Guys,

I seem to be in a spot of bother. I have two forms on one page and think the reason they are not working is because they are colliding with each other.

I am creating an online quoting system. On my estimate.php page it lists the items a customer would like.

form one with a submit button “update”. Customers can change quantities of their items and the update button updates these, so the form submits to itself.

update form


echo '<form action=' . $PHP_SELF . ' method="POST">';
echo '<input name='."cartQty[]".' type="text" value='.$quantity.' maxlength="4" size="4" />';
echo '<input type="submit" name="update" value="update" />';
echo '</form>';

form two with a submit button “view summary”. Once customers are happy with the items in their estimate they click on the view summary button and this carries all the information over to the summary.php page where it can be printed.

view summary form


echo '<form action="summary.php" onsubmit="return validate_form(this)" method="post">';
echo '<img src="images/servers'.$row['photo'].'" border="1" width="50px" height="50px" />';
echo ''.$title.'';
echo '&pound;'.$line_cost.'';
echo '<input name="id[]" type="hidden" value='.$product_id.' />';
echo '<a href="summary.php?title=&quantity=">Get Summary</a>';
echo '</form>';

Thats how they look seperatly but I want both the buttons at the button of the page so at the moment my estimate.php page looks more like this:


echo '<form action="summary.php" onsubmit="return validate_form(this)" method="post">';
echo '<form action=' . $PHP_SELF . ' method="POST">';
echo '<img src="images/servers'.$row['photo'].'" border="1" width="50px" height="50px" />';
echo ''.$title.'';
echo '<input name='."cartQty[]".' type="text" value='.$quantity.' maxlength="4" size="4" />';
echo '&pound;'.$line_cost.'';
echo '<input name="id[]" type="hidden" value='.$product_id.' />';
echo '<input type="submit" name="update" value="update" />';
echo '<a href="summary.php?title=&quantity=">Get Summary</a>';
echo '</form>';
echo '</form>';

I know that I could probably make the get summary button into a link instead and pass the variables that way but I didn’t really want to do that.

Any advice and help would be much appreciated.

Many thanks

Don’t embed one form within the other. Instead, separate them. You can still make the buttons appear next to each other with some smart CSS.

Could you go into more detail on how to seperate them please as I don’t know how to do this?

OR:
Seperate the two forms so that the one is not embedded within the other.
make two plain buttons (links styled with CSS to appear as buttons) and place them anywhere you like in the page. Use JavaScript to submit the first form when the first button is clicked:

button1.onclick = form1.submit();

Likewise, submit the second form (view summery) when the second button is clicked:

button2.onclick = form2.submit();

I have seperated my forms and created my CSS buttons and used the links below to display them.


<a id="about" href="estimate.php" title="update"></a>
<a id="about" href="summary.php" title="summary"></a>

I’m not sure where to include the javascript you suggested. Do they go within the forms or the links above?