Thread: 3 way form

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    2
    Rep Power
    0

    3 way form


    I am attempting to create a user survey and depending on whish radio button the user selects I want to take them to a different page. (minimal=thankyou.htm, medium=part2.cfm, high=part3.cfm).
    Obviously I also need to pass a unique identifier (ie the SOEID) so that I can update the particular record with the responses from the proceeding pages.
    I am no Cold Fusion guru, and am simply trying to modify the code UltraDev has given me.
    Any assistance would be greatly appreciated.

    part1.cfm
    ----------------------------------------------------

    <cfinclude template="../../Connections/data_access.cfm">
    <cfscript>
    // *** Edit Operations: declare variables

    // set the form action variable
    MM_editAction = CGI.SCRIPT_NAME;
    If (CGI.QUERY_STRING NEQ "") {
    MM_editAction = MM_editAction & "?" & CGI.QUERY_STRING;
    }

    // boolean to abort record edit
    MM_abortEdit = false;

    // query string to execute
    MM_editQuery = "";
    </cfscript>
    <cfscript>
    // *** Insert Record: set variables

    If (IsDefined("MM_insert")) {

    MM_editDatasource = #MM_data_access_DSN#;
    MM_editUserName = #MM_data_access_USERNAME#;
    MM_editPassword = #MM_data_access_PASSWORD#;
    MM_editTable = "main";
    MM_editRedirectUrl = "part2.cfm";
    MM_editRedirectUrl1 = "part3.cfm";
    MM_fieldsStr = "a1_1_soeid|value|a1_2_bus_name|value|a1_4_locn_id|value|a1_5_situation|value";
    MM_columnsStr = "a1_1_soeid|',none,''|a1_2_bus_name|',none,''|a1_4_locn_id|none,none,NULL|a1_5_situation|none,none,N ULL";

    // create the MM_fields and MM_columns arrays
    MM_fields = ListToArray(MM_fieldsStr,"|");
    MM_columns = ListToArray(MM_columnsStr,"|");

    // set the form values
    For (i=1; i+1 LE ArrayLen(MM_fields); i=i+2) {
    MM_fields[i+1] = IIf(IsDefined(MM_fields[i]),"FORM." & MM_fields[i],DE(""));
    }

    // append the query string to the redirect URL
    If (MM_editRedirectUrl NEQ "" AND CGI.QUERY_STRING NEQ "") {
    If (Find("?", MM_editRedirectUrl) EQ 0) {
    MM_editRedirectUrl = MM_editRedirectUrl & "?" & CGI.QUERY_STRING;
    } Else {
    MM_editRedirectUrl = MM_editRedirectUrl & "&" & CGI.QUERY_STRING;
    }
    }
    }
    </cfscript>
    <cfscript>
    // *** Insert Record: construct a sql insert statement

    If (IsDefined("MM_insert")) {

    // create the insert sql statement
    MM_tableValues="";
    MM_dbValues="";
    For (i=1; i+1 LE ArrayLen(MM_fields); i=i+2) {
    FormVal = MM_fields[i+1];
    MM_typesArray = ListToArray(MM_columns[i+1],",");
    Delim = IIf(MM_typesArray[1] NEQ "none","MM_typesArray[1]",DE(""));
    AltVal = IIf(MM_typesArray[2] NEQ "none","MM_typesArray[2]",DE(""));
    EmptyVal = IIf(MM_typesArray[3] NEQ "none","MM_typesArray[3]",DE(""));
    If (FormVal EQ "") {
    FormVal = EmptyVal;
    } Else {
    If (AltVal NEQ "") {
    FormVal = AltVal;
    } Else If (Delim EQ "'") { // escape quotes
    FormVal = "'" & Replace(FormVal,"'","''","ALL") & "'";
    } Else {
    FormVal = Delim & FormVal & Delim;
    }
    }
    If (i GT 1) {
    MM_tableValues = MM_tableValues & ",";
    MM_dbValues = MM_dbValues & ",";
    }
    MM_tableValues = MM_tableValues & MM_columns[i];
    MM_dbValues = MM_dbValues & FormVal;
    }
    MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")";
    }
    </cfscript>
    <cfif Not #MM_abortEdit# AND IsDefined("MM_insert")>
    <cfquery name="MM_editCmd" datasource=#MM_editDatasource# username=#MM_editUserName# password=#MM_editPassword#>
    #PreserveSingleQuotes(MM_editQuery)#
    </cfquery>
    <cfif isdefined('Form.a1_1_soeid')>
    <cfset client.soe = form.a1_1_soeid>
    </cfif>
    <cfif #MM_editRedirectUrl# NEQ "" AND #client.sit# EQ "a">
    <cflocation url="#MM_editRedirectUrl#" addtoken="no">
    <cfelse>
    <cflocation url="#MM_editRedirectUrl1#" addtoken="no">
    </cfif>
    </cfif>
    <cfquery name="main" datasource=#MM_data_access_DSN# username=#MM_data_access_USERNAME# password=#MM_data_access_PASSWORD#>
    SELECT * FROM main
    </cfquery>
    <cfquery name="business" datasource=#MM_data_access_DSN# username=#MM_data_access_USERNAME# password=#MM_data_access_PASSWORD#>
    SELECT * FROM business
    </cfquery>
    <cfquery name="locn" datasource=#MM_data_access_DSN# username=#MM_data_access_USERNAME# password=#MM_data_access_PASSWORD#>
    SELECT * FROM location
    </cfquery>
    <html>
    <head>
    <title>Access to Spatial Data</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    <!--
    function MM_goToURL() { //v3.0
    var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
    for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
    }
    //-->
    </script>
    </head>
    <body bgcolor="#FFFFFF" text="#000000">
    <div id="banner">Access to Spatial Data - User Needs Analysis</div>
    <div id="title">Part 1</div>
    <div id="content">
    <form method="post" action="<cfoutput>#MM_editAction#</cfoutput>" name="form1">
    <table align="center">
    <tr valign="baseline">
    <td nowrap align="right">A1_1_soeid:</td>
    <td>
    <input type="text" name="a1_1_soeid" size="20" maxlength="4">
    </td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right">A1_2_bus_name:</td>
    <td>
    <select name="a1_2_bus_name">
    <cfloop query="business">
    <option value="<cfoutput>#business.bus_id#</cfoutput>"><cfoutput>#business.department# | #business.bus_name#</cfoutput></option>
    </cfloop>
    </select>
    </td>
    </tr>
    <tr valign="baseline">
    <td nowrap align="right">A1_4_locn_id:</td>
    <td>
    <select name="a1_4_locn_id">
    <cfloop query="locn">
    <option value="<cfoutput>#locn.locn_id#</cfoutput>"><cfoutput>#locn.locndesc#</cfoutput></option>
    </cfloop>
    </select>
    </td>
    </tr>
    <tr>
    <td nowrap align="right" valign="top">A1_5_situation:</td>
    <td valign="baseline">
    <table align="left">
    <tr>
    <td>
    <input type="radio" value="1" name="a1_5_situation" <cfset sit = "a">>
    Minimal
    <td>
    </tr>
    <tr>
    <td>
    <input type="radio" value="2" name="a1_5_situation">
    Medium
    <td>
    </tr>
    <tr>
    <td>
    <input type="radio" value="3" name="a1_5_situation">
    High
    <td>
    </tr>
    </table>
    <p>
    <input type="submit" value="Minimal" onClick="MM_goToURL('parent','part2.cfm');return document.MM_returnValue">
    </p>
    <p>
    <input type="submit" value="Medium" onClick="MM_goToURL('parent','part3.cfm');return document.MM_returnValue">
    </p>
    <td nowrap align="right">&nbsp;</td>
    <td>
    <input type="submit" value="Insert Record">
    </td>
    </tr>
    </table>
    <input type="hidden" name="MM_insert" value="true">
    </form>
    </div>
    <div id="footer">footer</div>
    </body>
    </html>
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    My goodness, that code is pretty horrendous...did Ultradev generate that?

    Anyway, one way to handle it is to make the value for each radio button correspond to the page you want to run (part1, part2, part3). Then on the target page, do a cflocation based on the value of that form field. Something like:

    <cflocation url="http://mysite.com/#form.a1_5_situation#.cfm" />

    so if the user had picke option 2, the cflocation URL would become something like

    http://mysite.com/part2.cfm
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    2
    Rep Power
    0

    thanks, but...


    kiteless,
    thanks for your response. It sent me on the correct direction. The page now takes the user to the correct page depending on what radio button is selected.
    The next issue is, how do I pass the soe_id, preferably through the URL, to the next page and then use it to requery the main table so that I only update the correct record?
    I have only just started using cold fusion, so please forgive my ignorance!
    Thanks in advance.
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,286
    Rep Power
    968
    If the form has a field for soe_id then you don't have to pass it, it is already passed in the FORM scope when the form is submitted.

    Not sure what your app is meant to do, but before you go much further I would grab a copy of Ben Forta's CF book and read it. There are probably easier ways to do what you are trying to do but until you have a firmer grasp of CF they won't make much sense.

IMN logo majestic logo threadwatch logo seochat tools logo