Yes, it's possible to have multiple forms on one page and then submit them
all with one button. All you need to do is override the action that is
default with submit buttons.
In this example, One action will upload a file and the other will add
information in a database.
Because the button submit was inserting twice in my db, I had to substitute
it by a regular button.
One action I set along the code in 'action', and the other I write directly.
Good luck.
siomara
Bellow I am sending an example:
############################################################################
###################################
<!-- DocAccessPublishEditDocument.jsp -->
<!-- $$ BEGIN PAGE DIRECTIVE -->
<%@ page language = "java" %>
<%@ page import = "java.util.*" %>
<%@ page import = "FileSystemDBManager" %>
<!-- $$ END PAGE DIRECTIVE -->
<%
String header = request.getHeader("Host");
int documentID = 0;
String documentIDStr = "";
int parentFolderID = 0;
String parentFolderIDStr = "";
String title = "";
String notes = "";
String action = "";
String pipFormRef = "";
String formTitle = "";
String user = "Sio";
String relativePath = "Presentations";
HttpSession pipSession = request.getSession(false);
if (pipSession == null )
{
out.println("Session is NULL");
return;
}
String UserID = (String)pipSession.getAttribute("UserID");
String appName = PIPServices.pipProperties.getProperty("appName");
documentIDStr = request.getParameter("documentID");
parentFolderIDStr = request.getParameter("parentFolderID");
if (documentIDStr != null)
{
documentID = Integer.parseInt(documentIDStr);
}
if (parentFolderIDStr != null)
{
parentFolderID = Integer.parseInt(parentFolderIDStr);
}
if (documentID == 0)
{
pipFormRef = "addADocument_PF";
action = "http://" + header + "/" + appName +
"/servlet/PIP";
formTitle = "Add a Document";
}
else
{
pipFormRef = "updateDoc_PF";
action = "http://" + header + "/" + appName +
"/servlet/PIP";
formTitle = "Edit a Document";
PIPSnapRecset myPIPSnapRecset = null;
PipServerUtil myPIPUtilObj = null;
myPIPSnapRecset=
(PIPSnapRecset)pipSession.getAttribute("myPipSnapRecset");
myPIPUtilObj =
(PipServerUtil)pipSession.getAttribute("myPIPUtilObj");
String snapURL = "http://" + header + "/" +
appName +
"/servlet/PIP?request=execSnap&snapRef=getDocInfo&documentID=" +
documentID;
String snapoutputXML = myPIPUtilObj.LoadServlet(snapURL);
Hashtable srchResults = new Hashtable();
srchResults =myPIPSnapRecset.getDataFRec(snapoutputXML, 0,
srchResults);
title = (String) srchResults.get("title");
notes = (String) srchResults.get("notes");
}
%>
<script language=javascript>
////////////////////////////////////////////////////////////////////////////
///
// submit to appropriate servlet/jsp
//
function doFormSubmit()
{
objfrm1 = document.PublishEditDocument1;
objfrm1.action = "http://localhost:8100/pip6961/servlet/UploadServlet";
objfrm1.method = "post";
objfrm1.submit();
objfrm2 = document.PublishEditDocument2;
objfrm2.action = "<%=action%>";
objfrm2.method = "post";
objfrm2.submit();
}
</script>
<html>
<head>
<title> Portal </title>
</head>
<body>
<p> <b><font color="#008080" size="4">Uci </font><font
size="4">Wizard</font></b>
<font size="4">- <b>Publish Document</b></font>
</p>
<FORM name=PublishEditDocument1 enctype="multipart/form-data">
<table border="0" width="100%" height="227">
<tr>
<td width="10%" height="25">Document:</td>
<td width="90%" height="25"><input type=file size=20
name="fname"></td>
<input type="hidden" name="user" value="<%=user%>">
<input type="hidden" name="relativePath"
value="<%=relativePath%>">
</tr>
</table>
<p>
</p>
</form>
<FORM name=PublishEditDocument2>
<table border="0" width="100%" height="227">
<tr>
<td width="10%" height="25">Title:</td>
<td width="90%" height="25"><input type="text" name="title"
size="80" value="<%=title%>"></td>
</tr>
<tr>
<td width="10%" height="109" valign="top">Notes:</td>
<td width="90%" height="109" valign="top"><textarea rows="3"
name="notes" cols="69" value="<%=notes%>"></textarea></td>
</tr>
<tr>
<input type="hidden" name="documentID"
value="<%=documentID%>">
<input type="hidden" name="parentFolderID"
value="<%=parentFolderID%>">
<input type="hidden" name="pipFormRef"
value="<%=pipFormRef%>">
<input type="hidden" name="request"
value="execPIPForm">
<td width="10%" height="21"> </td>
<td width="90%" height="21"> </td>
</tr>
<tr>
<td width="10%" height="27"> </td>
<td width="90%" height="27">
<input type="button" value="Accept" name="btnAccept"
onclick="javascript:return
doFormSubmit()">
<input type="reset" name="btnReset" value="Cancel">
</td>
</tr>
</table>
<p>
</p>
</form>
</body>
</html>
############################################################################
###################################
The end
-----Original Message-----
From: Mattias Jiderhamn [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 08, 2001 4:15 AM
To: [EMAIL PROTECTED]
Subject: Submit multiple forms
Is it possible to have multiple forms on one page and then submit them
all with one button?
(IE only solution is ok).
I saw some guy trying to use
for(var i = 0; i < document.forms.length; i++)
document.forms[i].submit();
I don't find it very surprisingly it doesn't work. It seems this would
post all the forms, one at a time, to their (in this case the same)
action. (Like them having one submit each and you are fast enough to
click each of button.)
He was tipped to use enctype="multipart/form-data", which I know is used
for file uploads. But this should only affect one form (right?).
Or could I have a "multipart/form-data"-request consisting of several
forms?
How would you do that?
The whys:
The alternative to using multiple forms (still one Submit) would be
unique field names. If I have many similar fields (rows with the same
fields) I could use unique fieldnames (<imput name="id_1"), but I'd have
to extract each field in our business logic. If I have multiple forms
(or some kind of namespace) I could extract each form in my controller
and call the business logic for each form.
Pseudo code:
businessLogic( rowForm1.parameters );
businessLogic( rowForm2.parameters );
Could this be solved in any other way?
(For the moment we have one form with individual submit per row)
Mattias Jiderhamn
Expert Systems
[EMAIL PROTECTED]
==========================================================================To
unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets