Professional Web Applications Themes

how to reset a form with dynamic default values - Coldfusion - Getting Started

For an SQL-Statement I utilize a quiet complex form. Posting the form leads to a list of found database records. After the user looks at or edits a single record I'd like to be able to go back to the list from where a record was chosen to look at or edit. Therefor I need to create the query again with the values of the form as it was on posting. Since I also want the user to be able to reset the form to the default values (which are CF vars) I thought of storing the complete form in ...

  1. #1

    Default how to reset a form with dynamic default values

    For an SQL-Statement I utilize a quiet complex form.
    Posting the form leads to a list of found database records.
    After the user looks at or edits a single record I'd like to be able to go
    back to the list from where a record was chosen to look at or edit. Therefor I
    need to create the query again with the values of the form as it was on posting.

    Since I also want the user to be able to reset the form to the default values
    (which are CF vars) I thought of storing the complete form in the session.
    (twice actually: once with the default values and once with the user filled out
    values)

    Since the user may edit many records the actual form values have nothing to do
    with the values I need.

    I tried it somehow like in the attached code but it doesn't seem to work.

    Propably I made a stupid or silly mistake but what would be best practice for
    this kind of task?

    Any ideas or code samples of a working form...

    Thanks

    // before the form ever gets sent I define default values like this

    <cfparam name="form.EANCode" default="EAN-Code CU">
    <cfparam name="form.Lieferant" default="Lieferant">

    //and the form is like below,

    <tr>
    <td><label class="left" for="EANCode">EAN-Code CU</label></td>
    <td><cfoutput><input id="EANCode" name="EANCode" type="text" value="<cfif
    #form.EANCode# NEQ 'EANCode' AND Len(#form.EANCode#) GT
    0>#form.EANCode#<cfelse>EANCode</cfif>" onFocus="
    if(this.value=='#form.EANCode#' || this.value=='EANCode')this.value='';"
    onBlur="if(this.value=='')this.value='#EANCode#';"/></cfoutput></td>
    </tr>
    <tr>
    <td><label class="left" for="Lieferant">Lieferantenname</label></td>
    <td><cfoutput><input id="Lieferant" name="Lieferant" type="text"
    value="<cfif #form.Lieferant# NEQ 'Lieferant' AND Len(#form.Lieferant#) GT
    0>#form.Lieferant#<cfelse>Lieferant</cfif>" onFocus="
    if(this.value=='#form.Lieferant#' || this.value=='Lieferant')this.value='';"
    onBlur="if(this.value=='')this.value='#Lieferant#' ;"/></cfoutput></td>
    </tr>

    // before the form is sent I save the default values to the session:

    <cfif not StructKeyExists(session,"prodspecdefaultformvalues ")>
    <cfset session.prodspecdefaultformvalues = Duplicate(form)>
    </cfif>

    //posting calls the page again containing the form with a hidden form var
    which leads to including some different files and quering the db with the SQL
    WHERE clause constructed from the form values:

    <cfif #form.EANCode# NEQ "EAN-Code CU" AND #form.EANCode# NEQ "">
    AND (artikel_EAN LIKE '%#form.EANCode#%')
    </cfif>
    <cfif #form.Lieferant# NEQ "Lieferant" AND #form.Lieferant# NEQ "">
    AND (artikel_lieferantname LIKE '%#form.Lieferant#%')
    </cfif>

    // now coming back from editing some values I'd like to call the same page
    again but including another file again and the SQL should be constructed
    somehow like this:

    <cfif #session[prodspecfilledoutform.EANCode]# NEQ "EAN-Code CU" AND
    #session[prodspecfilledoutform.EANCode]# NEQ "">
    AND (artikel_EAN LIKE '%#session[prodspecfilledoutform.EANCode]#%')
    </cfif>
    <cfif #session[prodspecfilledoutform.Lieferant]# NEQ "Lieferant" AND
    #session[prodspecfilledoutform.Lieferant]# NEQ "">
    AND (artikel_lieferantname LIKE
    '%#session[prodspecfilledoutform.Lieferant]#%')
    </cfif>

    // of course I tried to get the filled out form values into the session on
    submit:

    <cfset session.prodspecfilledoutform = #form#>

    But some things propably are stupidly wrong.

    zu Guest

  2. #2

    Default Re: how to reset a form with dynamic default values

    Here is a simple example. The general principle will work with your great big
    form.

    <cfquery name="q1">
    select field1, field2
    from atable
    where primarykeyfield = something
    </cfquery>


    <cfscript>
    if (q1.recordcount is 1){
    f1= q1.field1;
    f2 = q1.field2;
    }
    else{
    f1="abc";
    f2=3;
    }
    <cfscript>

    <cfinput name = "input1" value="#f1#">
    <cfinput name = "input2" value="#f2#">


    Dan Guest

  3. #3

    Default Re: how to reset a form with dynamic default values

    thanks!
    I like the general principle although it's not exactly what I was looking for
    since the values in the form have nothing to do with the results in the query.

    the form gets a list of records from where I can edit a single record. no
    problems of filling the correct values there (although your principle might
    have been a slightly more elegant solution to use the exact same form for
    inserts and updates)

    but after edting a single record (which in reality is not that simple because
    a single record consists of data from several related tables) I' d like to go
    back to the filtered list from which I started the editing.

    No I always go back to the default list which is the first records from the
    unfiltered list (as if the form has not been sent yet)

    I still might use something like your example but depending on a parameter I
    need to fill the vars with the values of either
    session.prodspecdefaultformvalues or session.prodspecfilledoutform values (if
    that works)

    zu Guest

Similar Threads

  1. How to reset values with a webservice ?
    By ws98 in forum ASP.NET Web Services
    Replies: 1
    Last Post: March 4th, 02:24 PM
  2. Specifying dynamic default values for properties in custom controls:
    By Praveen Ramesh in forum ASP.NET Building Controls
    Replies: 0
    Last Post: September 2nd, 06:41 PM
  3. ASP.NET Reset Controls to default values question
    By psinyc in forum ASP.NET General
    Replies: 0
    Last Post: August 6th, 05:29 PM
  4. How to delete or reset Mozilla default printer
    By Ross Boylan in forum Debian
    Replies: 0
    Last Post: July 23rd, 02:40 AM
  5. Reset default CD-R options
    By Zeph in forum Mac Applications & Software
    Replies: 2
    Last Post: July 17th, 06:31 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139