Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to post multiple forms all at once?

Status
Not open for further replies.

dfwalton

Programmer
Jul 24, 2002
143
Here is my situation: I am entering timesheet information for all emps who worked a particular event. After selecting the event, I go to a page where the emp data is pulled from the db by <cfoutput query= blah>

I then have a form displaying and accepting data for each employee. Abbreviated, looks like this:

<cfoutput query=qryEmpInEvent>
<tr>
<form action= &quot;blah&quot; method = &quot;post&quot;>
<td> #qryEmpInEvent.EmpName#</td>
<td> <input type=&quot;text&quot; name=&quot;hours&quot; </td>
<td> <input type=&quot;submit&quot; value=&quot;Enter hours&quot;</td>
</form>
</tr>

I would like to know if there is a way to not have the submit by line, but for all 35 emps per event.

Thanks in advance for your help.

David
 
Maybe.

You can submit forms via javascript with the document.formname.submit() function. So on the submit button would call a function that loops through all the forms on your page and submits them.
But if it's crucial behavior (like, the app will break if all forms don't submit simultaneously) then I wouldn't count on javascript because it's just too easy to turn it off at the browser level.

But... perhaps there's a different way of looking at the problem. Any submit button in a given form will cause that form to submit... so you could have more than one submit button.

So maybe:
Code:
<form action= &quot;blah&quot; method = &quot;post&quot;>
<CFOUTPUT query=&quot;qryEmpInEvent&quot;>
<tr>
<td> #qryEmpInEvent.EmpName#</td>
<td> <input type=&quot;text&quot; name=&quot;hours&quot; </td>
<td> <input type=&quot;submit&quot; value=&quot;Enter hours&quot;</td>
</tr>
</CFOUTPUT>
</form>
is all you really need to do. Clicking any of the submit buttons would submit the entire form, and
Code:
#FORM.hours#
would contain a comma-delimited list of all the values entered in every hours field.

Of course... if all you get is a comma-delimited list of values, sometimes it's difficult to know which value goes with which record (in this case, employee).

A simple way around that is to name each field uniquely, based in part on some identifier for the employee in question.
Code:
<form action=&quot;blah&quot; method=&quot;post&quot;>
<CFOUTPUT query=&quot;qryEmpInEvent&quot;>
<tr>
<td>#qryEmpInEvent.EmpName#</td>
<td>
  <input type=&quot;text&quot; name=&quot;hours_#qryEmpInEvent.EmpID#&quot;> 
  <input type=&quot;hidden&quot; name=&quot;listIDs&quot; value=&quot;#qryEmpInEvent.EmpID#&quot;>  
</td>
<td><input type=&quot;submit&quot; value=&quot;Enter hours&quot;</td>
</tr>
</CFOUTPUT>
</form>
So, once the CFML has processed, the form looks something like this to the browser:
Code:
<form action=&quot;blah&quot; method=&quot;post&quot;>
<tr>
<td>Joe Smith</td>
<td>
  <input type=&quot;text&quot; name=&quot;hours_1&quot;> 
  <input type=&quot;hidden&quot; name=&quot;listIDs&quot; value=&quot;1&quot;>  
</td>
<td><input type=&quot;submit&quot; value=&quot;Enter hours&quot;</td>
</tr>
<tr>
<td>Jane Doe</td>
<td>
  <input type=&quot;text&quot; name=&quot;hours_2&quot;> 
  <input type=&quot;hidden&quot; name=&quot;listIDs&quot; value=&quot;2&quot;>  
</td>
<td><input type=&quot;submit&quot; value=&quot;Enter hours&quot;</td>
</tr>
<tr>
<td>Jeff Black</td>
<td>
  <input type=&quot;text&quot; name=&quot;hours_3&quot;> 
  <input type=&quot;hidden&quot; name=&quot;listIDs&quot; value=&quot;3&quot;>  
</td>
<td><input type=&quot;submit&quot; value=&quot;Enter hours&quot;</td>
</tr>
</form>
since all the hidden fields have the same name, in the action page
Code:
#FORM.listIDs#
will contain a convenient list of IDs that you can loop over and dynamically pull the value of the similarly-named hours field:
Code:
<CFLOOP list=&quot;#FORM.listIDs#&quot; index=&quot;whichID&quot;>
   <CFSET fieldValue = FORM[&quot;hours_#whichID#&quot;]>
   <CFOUTPUT>Employee ID: #whichID# entered #fieldValue# hours</CFOUTPUT><br />
</CFLOOP>


-Carl
 
I don't want to sound that I love the CFGRID tag, but, it is great and it sounds like it might give you what you want. All the employees can be listed, user updates everyone and then submits. Done. CFGRID solve I similar challenge for me, I'm sure it will help you out. The most common issue is that you must have a certain version of JRE. Other than that, it should work.
 
Wow... I don't think I've ever seen the words &quot;CFGRID&quot; and &quot;great&quot; in the same post before.


-Carl
 
I want to thank both Carl and CidMatrix. Being quite new to this, there are many mysteries still unexplored, CFGRID amongst them. It (CFGRID) sounds from the documenation like it is exactly what I need, but Carl's reply has me a little anxious -- could you elaborate?

I any event I will investigate both options you two laid out, and appreciate your guidance.

David
 
Well, it's like Carl said in another post recently, in order for CFGRID to work properly, you need to have a certain level of control / assurance that the client machine will meet certain criteria, i.e. JRE version.

I for one like using CFGRID, it resolve my issue completely; however, I do have complete control of the machines that will be using it.

So, in a nutshell, CFGRID is not for every challenge that requires updating of multiple records, but, in certain situations it will work.
 
<noscript><META HTTP-EQUIV=&quot;refresh&quot; CONTENT=&quot;0; URL=/nojavascript.htm&quot;></noscript>

Javascript's WAY too useful, fast, and thin to discard because someone doesn't &quot;like&quot; it. I use it for everything from menuing to field validation to whatever I can use it for. I'm not planting garbage on the user's box; I'm not popping up useless ad windows; I'm not annoying the user. Everything I use JS for has a legitimate business function within the confines of my application. Not ONE of my customers has complained because they have to use it on my site.

Phil Hegedusich
Senior Web Developer
IIMAK
-----------
Boy howdy, my Liberal Studies degree really prepared me for this....
 
That's why I qualified my comment with &quot;if it's crucial behavior&quot;, Phil.

Javascript does have it's place. But you shouldn't count on it for crucial functionality... like making sure your database is updated properly, as in this case.

Using javascript for menuing is just fine, because usually the biggest detriment is that a pull-down menu doesn't appear. But if you design your site correctly, the user can still click on the menu anchor and get around.

Javascript form validation, too, can be helpful to the user.

And I never said I &quot;didn't like&quot; javascript.

But something like this... where you need to have multiple forms submit via javascript, otherwise your database will be corrupt or incomplete... it's not a good idea to put all your eggs in the javascript basket.


-Carl
 
OK, some clarification:

Javascript takes care of user choices for me (&quot;Add to the order&quot;; &quot;Check Out&quot;; etc.), and performs data validations without a server round-trip. These are &quot;crucial functions&quot;, and they work just fine for my app, thank you.

I didn't say that you didn't like JS, Carl. It's the user who turns it off that doesn't like it.

Phil Hegedusich
Senior Web Developer
IIMAK
-----------
Boy howdy, my Liberal Studies degree really prepared me for this....
 
So how does a user who &quot;doesn't like javascript&quot; and turns it off happen to add anything to their order or check out?



-Carl
 
<noscript><META HTTP-EQUIV=&quot;refresh&quot; CONTENT=&quot;0; URL=/nojavascript.htm&quot;></noscript>

They never start one in the first place.

Phil Hegedusich
Senior Web Developer
IIMAK
-----------
Boy howdy, my Liberal Studies degree really prepared me for this....
 
Soooo... this begs the question... what if the next person who wants to give you a $5 million dollar order just happens to have javascript turned off?

You've just told them that you don't consider their business to be valuable enough to provide an alternative... or not base your online commerce on javascript in the first place.


-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top