Copy link to clipboard
Copied
I have the following code in my action page, and it works.
<cfif form.urdn_action is "1">
<cfif StructKeyExists(form, "fieldnames")>
<cfloop index="i" list="#trim(form.fieldnames)#">
<cfif ListFirst(i, "/") is "comments">
<cfset select_urdn_number = listgetat(i, 2, "/")>
<cfset select_urdn_line_item = listlast(i, "/")>
<cfset combineEnd = select_urdn_number & "/" & select_urdn_line_item>
<cfif StructKeyExists(form, "del/" & combineEnd) and form["del/" & combineEnd] is "Yes">
<cfset select_comments = form["comments/" & combineEnd]>
..then update table below.....
However,when I switch it to one form only, (no action page, submitting to it self), I change it slightly by adding
<cfif structkeyexists(form, "btnSubmit")> before everyting else.
<cfif structkeyexists(form, "btnSubmit")>
<cfif form.urdn_action is "1">
<cfif StructKeyExists(form, "fieldnames")>
<cfloop index="i" list="#trim(form.fieldnames)#">
<cfif ListFirst(i, "/") is "comments">
<cfset select_urdn_number = listgetat(i, 2, "/")>
<cfset select_urdn_line_item = listlast(i, "/")>
<cfset combineEnd = select_urdn_number & "/" & select_urdn_line_item>
<cfif StructKeyExists(form, "del/" & combineEnd) and form["del/" & combineEnd] is "Yes">
<cfset select_comments = form["comments/" & combineEnd]>
...then update tables....
Now the tables are not being updated. Why did the extra cfif structkeyexists prevent the form from working now ?
Copy link to clipboard
Copied
You only have to check for the form being submitted once. It either was or it wasn't. You have 3 checks.
Try cfdumping your form and see it you have anything called btnSubmit.
Copy link to clipboard
Copied
I have not used cfdump before but googled. Is it somethign like <cfdump var = "#form#">, and where do I put it ?
Also my submit button is :
<input type="submit" style="width: 108px" name="btnSubmit" value="Submit"></td>
why would it not be found ?
Copy link to clipboard
Copied
You put <cfdump var="#form#"> at the very first spot where you expect your form variables to exist.
When I am if/else-ing stuff and have problems, I de-bug as follows.
if what I expect
yes
else
output all relevent data
Copy link to clipboard
Copied
OK, I got the cfdump to display all the form variables, and my submit button, btnSubmit is there. But I think that is also the problem.
In my original action page, I did not have to check for the existence of the submit button, so the codes below worked :
<cfif ListFirst(i,"/") is "comments">
<cfset select_urdn_number = listgetat(i, 2, "/")>
<cfset select_urdn_line_item = listlast(i, "/")>
<cfset combineEnd = select_urdn_number & "/" & select_urdn_line_item>
<cfif StructKeyExists(form, "del/" & combineEnd) and form["del/" & combineEnd] is "Yes">
Now when I submit the form to itself, I have to check for the existence of the submit button and that gives me an extra form variable, so
<cfif ListFirst(i,"/") is "comments"> will fail since it is no loner the first variable.
So instead of performing listfirst, how can I find the comments in the form variables, so that I can continue to perform the other steps after ListFirst,
to get all the information that I want ? I need it broken up like the above in order for the form to process correctly.
Copy link to clipboard
Copied
When I loop through form variables, I don't really care what order they are in. I do things like this:
<cfloop list="#form.fieldnames#" index = "thisfield">
<cfif thisfield is "something">
code
<cfelseif left(thisfield, 7) is "whatever">
code
etc
Copy link to clipboard
Copied
The name of my comments field is defined as name="comments/#urdn_number#/#urdn_line_item#", so basically, each urdn_number (like request number) can/will have one of more line items and comments. So when I update the comments for each urdn_number, I need to know which line item it corresponds to, thus the ListFirst, listgetat, etc., code to extract the urdn_number and line_item_number.
In your example, your variable thisfield is what, one of the form fields ? So you are just checking the form field for the existence of that value ?
In my code, how would that be defined if I have name="comments/#urdn_number#/#urdn_line_item#" ?
Copy link to clipboard
Copied
You are attempting something difficult in that you have two variables as part of your form field names and it appears that you haven't mastered the concept of processing form fields with just 1 variable as part of their name. You might want to step back from your current project and do a tutorial on the slightly simpler version.
When I do this,
<cfloop list="#form.fieldnames#" index="thisfield">
Thisfield is the name of the form field. If I want to see what was submitted for that field, it's
#form[thisfield]#
You don't have to check to see if it's defined, because you know it is. Otherwise it wouldn't be in the list. You can check to see if it has a value, or if it's a number, or a date, or anything else that's relevent.
Copy link to clipboard
Copied
There is no need for all the IFs. In the first case, <cfif StructKeyExists(form, "fieldnames")> should have come before <cfif form.urdn_action is "1"> anyway. This is because, once a form is submitted, Coldfusion automatically creates the list form.fieldnames. In fact, it is suffiecient in both cases to use <cfif isDefined("form.urdn_action") and form.urdn_action is "1">
Copy link to clipboard
Copied
I will have to test once the server is back up from maintenance.
So I do not have to check to see if the submit button was clicked. I just check to see if the radio button was selected and which one was selected, value 1 or 2. ?
So when I first enter the page, the radio button will not be there so it will pass thru straight to the form itself. when I check the first radio button and submit the form to itself, the radio button is now there with a value, of 1 so <cfif isDefined("form.urdn_action") and form.urdn_action is "1"> is now true, and the rest of the code, ListFirst, etc., should then all work like before, since the extra form variable is no longer there ?
Am I understanding this correctly now ?