Skip to main content
Known Participant
September 4, 2009
Question

Why won't this work now ?

  • September 4, 2009
  • 2 replies
  • 1235 views

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 ?

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    September 6, 2009

    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">

    Known Participant
    September 6, 2009

    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 ?

    Inspiring
    September 4, 2009

    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.

    Known Participant
    September 5, 2009

    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 ?

    Inspiring
    September 6, 2009

    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#" ?


    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.