Validating Insert Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmorand
    New Member
    • Sep 2007
    • 219

    #1

    Validating Insert Query

    I've got an enter/edit screen created for people to enter new systems. Before the new system gets submitted I have the submit page query the database to make sure that a record doesn't already exist with that name. If it does, I set the url back to the enter/edit screen. Is there a way I can have the coldfusion popup a message stating that the user entered an entry that already exists?

    Here is a snipped from the submit page:

    [CODE=cfm]
    <cfif isDefined("Form .Add")>
    <cfquery name="validateN ame" datasource="Sec urity_Access" dbtype="ODBC">
    select sysID from tblSystem
    where name='#Form.nam e#'
    </cfquery>
    <cfif "validateName.R ecordCount" eq 1>
    <cflocation URL="system.cfm ">
    <cfelse>
    ............... ..
    [/CODE]
    Last edited by acoder; Sep 27 '07, 06:56 PM. Reason: fixed code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You can popup a message using JavaScript. You could pass a variable in the url to show that validation failed and check that to show the popup in the original page.

    Alternatively, just show an error message on screen.

    Comment

    • dmorand
      New Member
      • Sep 2007
      • 219

      #3
      Excellent thanks!!

      Will CF create the javascript for me? I don't really know javascript all that well, so I've been relying on the javascript that CF creates.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by dmorand
        Excellent thanks!!

        Will CF create the javascript for me? I don't really know javascript all that well, so I've been relying on the javascript that CF creates.
        If you just want a simple alert, the Javascript is very easy, e.g.
        [code=javascript]alert("You entered an entry that already exists!");[/code]

        Of course, you would use Coldfusion to check first and then put the Javascript within <script> tags, e.g.
        [CODE=cfm]<cfif isDefined("url. error")>
        <script>...</script>
        </cfif>[/CODE]

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          One other alternative is to post to the same page, i.e. your form and action pages are the same. In this way, if there is an error, you can display the alert and then display the form again, instead of using cflocation.

          Comment

          • dmorand
            New Member
            • Sep 2007
            • 219

            #6
            Originally posted by acoder
            One other alternative is to post to the same page, i.e. your form and action pages are the same. In this way, if there is an error, you can display the alert and then display the form again, instead of using cflocation.
            That's a good idea, I should look into implementing that.

            Comment

            Working...