OK.  Assuming that the submitted page contains ALL the requests for the
class, you don't really care what the current vs. original status is for
each item, right?  You only care if the total "registered" GT "class size".


You could do something like,
(pseudo code)
get maxClassSize
set registeredCount = 0
LOOP formfields
        IF formfield name is one you're interested in and value =
'registered'
                increment registeredCount
        ENDIF
ENDLOOP

IF registeredCount > maxClassSize
        abort
ENDIF

UPDATE DB


Of course, the admin is going to be bummed out if you don't return the
selected values on the form for them to resubmit.  In addition, your server
has to spend time processing invalid input. This seems like a good
opportunity for some client-side validation.  When the user clicks the form
Submit button, you could loop through the appropriate form fields and get
the "registered" count; you could compare this to the maxClassSize, stored
in a hidden form field or a javascript variable .  If the value is too high,
display an alert, and interrupt the processing.

I don't know what your experience is with JavaScript, but it's the same
psuedo-code as your CF page.  One important piece of JavaScript knowledge is
that the form elements form a collection you can loop through.  You also
need to give the relevant fields a similar prefix.


function validateForm(){
        var registeredCount = 0;
        for (i=0;i<document.formname.length;i++){
                if (left(document.formname.elements(i).name, 11) =
"status_name") 
                        if (document.formname.elements(i).value = "1")
                                registeredCount = registeredCount + 1;
        }
        if (registeredCount > maxClassSize){
                alert('The maximum class size is " & maxClassSize & ".");
                return false;
        }
        return true;
}

Of course, if you're using VBScript, the syntax is different.  Good luck.

        


-----Original Message-----
From: Terri Stocke [mailto:[EMAIL PROTECTED]]
Sent: Sunday, September 24, 2000 3:46 PM
To: CF-Talk
Subject: comparing original data with user inputted changes


All,

I'm still struggling with this particular piece of funtionality, so I'm 
reposting...

I'm working on a class approval app where employees fill out a form to 
request management approval to enroll in a company sponsored class.

An admin can go in and view all requests for each particular class, and 
change each request status (registered, wait list, pending approval, not 
approved, cancelled) via a dropdown list for each record. She can make all 
of her changes on the one screen, and click submit to update all of the 
records at once (via a loop in the update query in the action page).

Now, I don't want the admin to make the mistake of overbooking the class. 
So, I pass a hidden field with each record to indicate what the original 
status was for each record. Then in the action page, I'm trying to compare 
the original status with the status the user (may have) changed it to. If 
the admin changed a status to "registered" (represented by the value "1"), 
then I want the registered_count to increment. I then want to compare the 
registered_count to the maximum class size. If it has been exceeded, I want 
to display a CFABORT error message before any data is even written to the 
database.

This is what I've tried so far, but unfortunately, this is still allowing me

to register beyond the class capacity:

<cfloop list="#form.fieldnames#" index="ThisRow">
        <cfloop from="1" to="#numrecords#" index="current">
        <cfset new_status=#Evaluate("status_name" & current)#>
        <cfset original_status=#Evaluate("original_status" & current)#>
        <cfif (original_status NEQ 1 OR original_status IS "") AND
new_status EQ 1>
        <cfset
registered_count=#incrementValue(registered.registered_count)#>
        <cfset new_registered_count=#incrementValue(registered_count)#>
                <cfelse>
        <cfset new_registered_count=0>
        </cfif>
        </cfloop>
</cfloop>

Any suggestions?

Thanks!
Terri
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

Share information about yourself, create your own public profile at 
http://profiles.msn.com.

----------------------------------------------------------------------------
--
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or
send a message to [EMAIL PROTECTED] with 'unsubscribe' in
the body.
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to