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

    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