?
Solved

executing multiple submit buttons on a single page

Posted on 2005-03-02
6
Medium Priority
?
1,550 Views
Last Modified: 2013-12-24
hi, i have the following two forms on the SAME page. both forms submit to the same page also (i.e page2.cfm).
is it possible to make it so that I also have one "Submit All" button that will submit both the forms.

i could put all the inputs into a single form but wanted to give the ability to submit the individual forms also.

<cfform name="Form1" action="page2.cfm" method="POST">
<tr>
<td><cfinput name="input1" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><cfinput name="input2" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><input name="Submit" type="Submit" value="Submit"></td>
</tr>
</cfform>

<cfform name="Form2" action="page2.cfm" method="POST">
<tr>
<td><cfinput name="input1" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><cfinput name="input2" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><input name="Submit" type="Submit" value="Submit"></td>
</tr>
</cfform>
0
Comment
Question by:Judy Deo
6 Comments
 
LVL 5

Assisted Solution

by:kkhipple
kkhipple earned 1000 total points
ID: 13443793
its possible... hwoever, i think the easiest way to do it is if you have one form  with three submit buttons

depending on which submit button the user clicks on, you collect certain info from the form...


i hope that gets you started..


<cfform name="Form1" action="page2.cfm" method="POST">
<tr>
<td><cfinput name="input1" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><cfinput name="input2" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><input name="Submit1" type="Submit" value="Submit"></td>
</tr>
<tr>
<td><cfinput name="input1" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><cfinput name="input2" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><input name="Submit2" type="Submit" value="Submit"></td>
</tr>
<tr>
<td><input name="Submit3" type="Submit" value="Submit All"></td>
</tr>
</cfform>




page2.cfm


<CFIF FORM.Submit EQ 'Submit1'>

<CFELSEIF FORM.Submit EQ 'Submit2'>

<CFELSEIF FORM.Submit EQ 'Submit3'>

</CFIF>
0
 
LVL 7

Assisted Solution

by:INSDivision6
INSDivision6 earned 100 total points
ID: 13444001
Only using JScript
0
 
LVL 17

Assisted Solution

by:Tacobell777
Tacobell777 earned 200 total points
ID: 13444604
<script>
function submitAll()
{
    document.Form1.submit();
    document.Form2.submit();
}
</script>


<input name="Submit3" type="Submit" onclick="submitAll();" value="Submit All">

BUT ( a big but ) this would not work unless you set the target of the form to be _blank
otherwise the first submit would submit the form from the page itself and not submit the next one...
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 200 total points
ID: 13445280
It is actually a bad idea and will not work in a lot of cases (especially problems using cfform)

What you should do is have one form.

Then have as many submit buttons as you like.

The page you submit to tests to see which button was clicked.

If only submit1 is clicked then it acts as if only the fields that used to be part of the first form were submitted.

If submit 2 is cliced it only looks at the fields from the second part.

If the submitall is clicked then it looks at all of the fields.


This way you have the flexibility you want, but also have proper coding.
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 13445282
Oh I just realised that kkhipple gave you the code for this.  :o)  I overlooked that post at first....
0
 
LVL 14

Accepted Solution

by:
Renante Entera earned 500 total points
ID: 13446049
Hi sagardeo!

Just a correction on the posted code of kkhipple.  'Coz if you run that code, you might encountered problems like :
  1.  Input field "input1" is not unique.
  2.  Element "Submit" is not defined on the form.

Here's the revised one :

<!--- Take note on the name of the submit button.  It should be "Submit" 'coz you will refer to this on your submit page. --->
<cfform name="Form1" action="page2.cfm" method="POST">
<tr>
<td><cfinput name="input1" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><cfinput name="input2" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><input name="Submit" type="Submit" value="Submit1"></td>
</tr>
<tr>
<td><cfinput name="input3" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><cfinput name="input4" type="Text" size="5" validate="integer" required="Yes"></cfinput></td>
<td><input name="Submit" type="Submit" value="Submit2"></td>
</tr>
<tr>
<td><input name="Submit" type="Submit" value="Submit All"></td>
</tr>
</cfform>

:: page2.cfm ::
<!--- It would be better if you use "<cfswitch>" tag --->
<cfswitch expression="#form.Submit#">
  <cfcase value="Submit1">
    Submit 1
  </cfcase>
  <cfcase value="Submit2">
    Submit 2
  </cfcase>
  <cfdefaultcase>
    Submit All <!--- which is the default --->
  </cfdefaultcase>
</cfswitch>

Hope this helps you.  Just try it.


Goodluck!
eNTRANCE2002 :-)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question