Skip to main content
Known Participant
May 14, 2008
Question

Error messages insert

  • May 14, 2008
  • 2 replies
  • 337 views
I was given the code below and I just added the query.

The problem I am having is the error messages. I am not sure where they go.

I have a form with checkboxes and comments.

If they submit without checking a box, then it should
return to the form and popup an error message.

If they check a box but do not enter comments, then it
should return to the form with an error message.

It they check at least one box and enter comments,
then it should go to another screen with a successful
message.

Everything seems to work except for the last record
remaining. For example, if there are three line items
and the first two are deleted, it returns to the form
and popsup the checkbox error message, which it should
not. It should be redirected to another page with a
successful message.

I think I just have the messages in the wrong spot.

Here is the code :

<cfif StructKeyExists( form, "fieldnames" )>
<cfloop index="i" list="#trim( form.fieldnames) #">
<cfif ListFirst(i, "/") is "comments">
<cfset select_ref_number = listgetat(i, 2,
"/")>
<cfset select_ref_line_ item = listlast(i,
"/")>
<cfset combineEnd = select_ref_number & "/"
& select_ref_line_ item>

<!--- Add this to check for the checkbox --->
<cfif StructKeyExists( form, "del/" &
combineEnd) and form["del/" & combineEnd] is "Yes">
<cfset commentsName = "comments/" &
combineEnd>

<cfset select_comments =
form[commentsName] >

<cfif len(trim(select_ comments) ) eq 0>
If comments are blank, return to form with comments <==== error message
required error
</cfif>

<cfquery name="qryUpdate_ ref_Line_ Items"
datasource=" recDisc">
update test_UnReceivables_ ref_Line_ Items
set current_state = 'Voided'
where ref_number = '#select_ref_ number#'
and ref_line_item = '#select_ref_ line_item# '
</cfquery>

<cfquery name="qryInsert_ Activity_ Log"
datasource=" recDisc">
insert into test_UnReceivables_ Activity_ Log
(activity_transacti on_id,
activity_id,
user_employee_ number,
activity_date,
comments,
ref_number,
line_item)

values
('#act_txn_id# ',
'7',
'#cgi.remote_ user#',
#createODBCDateTime (Now())#,
'#select_comments# ',
'#select_ref_ number#',
'#select_ref_ line_item# ')
</cfquery>
</cfif>

</cfif>
</cfloop>

If no checkbox is selected, return to form here and <==== error message
display checkbox error message
<cfelse>

If everythign passes, redirect to another page and <===== message
display a successful message

</cfif>

Thanks for your help.

    This topic has been closed for replies.

    2 replies

    Inspiring
    May 14, 2008
    Olivia Crazy Horse wrote:

    > Here is the code :
    >
    > <cfif StructKeyExists( form, "fieldnames" )>
    > <cfloop index="i" list="#trim( form.fieldnames) #">
    > <cfif ListFirst(i, "/") is "comments">
    > <cfset select_ref_number = listgetat(i, 2,
    > "/")>
    > <cfset select_ref_line_ item = listlast(i,
    > "/")>
    > <cfset combineEnd = select_ref_number & "/"
    > & select_ref_line_ item>
    >
    > <!--- Add this to check for the checkbox --->
    > <cfif StructKeyExists( form, "del/" &
    > combineEnd) and form["del/" & combineEnd] is "Yes">

    checking for form["del/" & combineEnd] is "Yes" is not needed as a check
    box will be defined in form only if selected - thus it will never be
    "No". furthermore, if you later decide to give your checkboxes a
    different value, like 1, you will have to re-write this code...

    > <cfset commentsName = "comments/" &
    > combineEnd>
    >
    > <cfset select_comments =
    > form[commentsName] >
    >

    the above 2 lines of code are totaly innecessary - you already have it
    all in the loop index (i). just use form in the following code
    instead of select_comments

    > <cfif len(trim(select_ comments) ) eq 0>
    > If comments are blank, return to form with comments <==== error message
    > required error
    > </cfif>
    >
    > <cfquery name="qryUpdate_ ref_Line_ Items"
    .....
    > </cfquery>
    > </cfif>
    >
    > </cfif>
    > </cfloop>
    >
    > If no checkbox is selected, return to form here and <==== error message
    > display checkbox error message

    OK, to be here, in this place in your code, only one condition must be
    met - <cfif StructKeyExists( form, "fieldnames" )>. obviously, if this
    is an action page for a from it will ALWAYS [well, unless you have NO
    form elements inside your form] be TRUE.

    > <cfelse>

    This part hence will NEVER execute...

    >
    > If everythign passes, redirect to another page and <===== message
    > display a successful message
    >
    > </cfif>
    >
    > Thanks for your help.
    >
    >
    >



    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    May 14, 2008
    Here's what I do...

    1 - I create a structure

    <cfset message = structNew(); />

    2 - Then I add things into this structure, like an error type and an error message.

    <cfif len(trim(select_ comments) ) eq 0>
    <cfset message.info = "Please enter blah..." />
    <cfset message.type = "error" />
    </cfif>

    3 - Then, on your page you check if these structure keys exist

    <cfif structKeyExists(message, "info") and structKeyExists(message, "type")>
    <cfoutput>
    <p class="#message.type#">#message.info#</p>
    </cfoutput>
    </cfif>


    There are better ways, and this could have errors (just wrote it on the fly) but it should give you a good enough idea.

    Thanks,
    Mikey.
    Known Participant
    May 14, 2008
    Thanks for the response.

    The code works and the error messages do display properly. But like I said, after everything is done, it should be redirected to another page with a succesful update message. Instead, it is returning to the form and displaying the comment required message.

    I think my messages are not in the right place and I just need to know where they go, so that the messages display properly.

    Thanks