Skip to main content
Participating Frequently
February 3, 2012
Answered

Redirect to two separate pages in the same cfform

  • February 3, 2012
  • 4 replies
  • 2812 views

I'm a bit of a novice at this.Hoping someone can guide me on how to accomplish this. I have a simple selection list (below). If they user chooses the selection in red I want it to redirect them to a page other than the one in the cfform tag, but I can't figure out how to segregate the options within the cfform from the same list. Thanks in advance.

<cfform action="index2.cfm" method="POST">

<table align="center" width="475" border="0" cellpadding="1" cellspacing="0">

<tbody>

<tr>

<td><span class="label">Select Version:</span> </td>

<td>

  <cfselect name = "UPVersion">

   <option value=""></option>

   <option value="66SP1">6.6 SP1x</option>

   <option value="66SP2">6.6 SP2x</option>

  <option value="701">7.0.1x</option>

  </cfselect>

</td>

</tr>

<input type="hidden" name="gosearch" value="gosearch">

<input type="hidden" name="Rows" value="50">

<tr>

<td colspan="3" align="center"><input type="submit" name="Submit" value="[ search ]"> <input type="reset" name="reset" value="[ clear ]"></td>

</tr>

</tbody>

</table>

</cfform>

    This topic has been closed for replies.
    Correct answer BKBK

    mostlyconfused wrote:

    I'm a bit of a novice at this.Hoping someone can guide me on how to accomplish this. I have a simple selection list (below). If they user chooses the selection in red I want it to redirect them to a page other than the one in the cfform tag, but I can't figure out how to segregate the options within the cfform from the same list. Thanks in advance.

    <cfform action="index2.cfm" method="POST">

    <table align="center" width="475" border="0" cellpadding="1" cellspacing="0">

    <tbody>

    <tr>

    <td><span class="label">Select Version:</span> </td>

    <td>

      <cfselect name = "UPVersion">

       <option value=""></option>

       <option value="66SP1">6.6 SP1x</option>

       <option value="66SP2">6.6 SP2x</option>

      <option value="701">7.0.1x</option>

      </cfselect>

    </td>

    </tr>

    <input type="hidden" name="gosearch" value="gosearch">

    <input type="hidden" name="Rows" value="50">

    <tr>

    <td colspan="3" align="center"><input type="submit" name="Submit" value="[ search ]"> <input type="reset" name="reset" value="[ clear ]"></td>

    </tr>

    </tbody>

    </table>

    </cfform>

    There just might be too many moving parts for the novice to keep track of. Start off with something like

    <script type="text/javascript">

    function getVersion()

    {

        var version = document.getElementById('UPVersion').value;

        if (version == '701') {

            window.location="some_other_page.cfm";

        }

    }

    </script>

    <cfform action="index2.cfm" method="POST">

      <cfselect name = "UPVersion" id="UPVersion" onchange="getVersion()">

      </cfselect>

    </cfform>

    4 replies

    Inspiring
    February 7, 2012

    I use what I call a direction page to send user to different action pages depending upon a selection criteria.

    I use hidden fields to retain the value of the form fields

    <CFIF #Form.X#  EQ 1>

         <cfloop list="#Form.FieldNames#" index="i">

              <input type="hidden" name="#i#" value="#Evaluate("Form." & "#i#")#" />

         </cfloop>

         <CFLOCATION Url = "process1.cfm">

    <CFLESE>

           <cfloop list="#Form.FieldNames#" index="i">
              <input type="hidden" name="#i#" value="#Evaluate("Form." & "#i#")#" />

         </cfloop>

         <CFLOCATION Url = "process2.cfm">

    </CFIF>

    Legend
    February 7, 2012

    Your hidden field logic is not working. The cflocation tag uses a 404 page moved response (I think it's 404), and this response does not support form field variables. You can use a form with hidden fields and then use javascript to submit the form, or you can use URL variables to pass this information in the cflocation call (... "process2.cfm?field1=xxx&field2=yy..."), but not form fields directly like in your sample code.

    Inspiring
    February 7, 2012

    The sample code I provided is reduced down to show a concept of how I solved the multiple processing based upon user selection criteria. 

    Looping throught the FORM.FIELDNAMES was provided as an easy way to capture the fieldnames and their values.

    Process1,cfm and Process2.cfm were used to show 2 different processing pages.  They do not exist and are examples.

    I use this logic on many pages and it works well. 

    You are correct that you need to further refine the code using the javascript or URL to pass the form variables.

    <CFLOOP list="#Form.FieldNames#" index="i">

         <CFIF CurrentRow EQ 1>

                                          <CFSET z = "?#i# & "=" & #Evaluate("Form." & "#i#")#">

         <CFElSE>

                                          <CFSET z = #z# &", " & "#i# & "=" & #Evaluate("Form." & "#i#")#">

         </CFIF>

    </CFLOOP>

    <CFIF #Form.X#  EQ 1>

         <CFLOCATION Url = "process1.cfm#z#">

    <CFELSE>

         <CFLOCATION Url = "process2.cfm#z#">

    </CFIF>

    You could also process both functions on one page.

    <CFIF IsDefined("Form.UPVersion") and #Form.UPVersion# EQ "7.0.1x">

         Do special processing

    <CFELSE>

         Do Normal Processing

    </CFIF>


    Participating Frequently
    February 6, 2012

    Thank you all for your assistance!

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    February 4, 2012

    mostlyconfused wrote:

    I'm a bit of a novice at this.Hoping someone can guide me on how to accomplish this. I have a simple selection list (below). If they user chooses the selection in red I want it to redirect them to a page other than the one in the cfform tag, but I can't figure out how to segregate the options within the cfform from the same list. Thanks in advance.

    <cfform action="index2.cfm" method="POST">

    <table align="center" width="475" border="0" cellpadding="1" cellspacing="0">

    <tbody>

    <tr>

    <td><span class="label">Select Version:</span> </td>

    <td>

      <cfselect name = "UPVersion">

       <option value=""></option>

       <option value="66SP1">6.6 SP1x</option>

       <option value="66SP2">6.6 SP2x</option>

      <option value="701">7.0.1x</option>

      </cfselect>

    </td>

    </tr>

    <input type="hidden" name="gosearch" value="gosearch">

    <input type="hidden" name="Rows" value="50">

    <tr>

    <td colspan="3" align="center"><input type="submit" name="Submit" value="[ search ]"> <input type="reset" name="reset" value="[ clear ]"></td>

    </tr>

    </tbody>

    </table>

    </cfform>

    There just might be too many moving parts for the novice to keep track of. Start off with something like

    <script type="text/javascript">

    function getVersion()

    {

        var version = document.getElementById('UPVersion').value;

        if (version == '701') {

            window.location="some_other_page.cfm";

        }

    }

    </script>

    <cfform action="index2.cfm" method="POST">

      <cfselect name = "UPVersion" id="UPVersion" onchange="getVersion()">

      </cfselect>

    </cfform>

    Participating Frequently
    February 6, 2012

    Thank you very much for taking the time to spell it out. I did find something similar to this in google, but this is much cleaner as far as helping me understand what is actually happening

    Legend
    February 3, 2012

    If non-javascript support is a requirement, you'll need to add code to index2.cfm to send the user to the new page via a cflocation call when UPVerson=701.

    If javascript is a requirment, then it would be fairly simple add an onsubmit event to either change the action of the form or simply do a location change.

    Participating Frequently
    February 3, 2012

    Thank you for the quick response. I'm afraid 'novice' should be emphasized. Do you have a sample piece of code that would illustrate the process in your second suggestion, or is there a tutorial anywhere I could look at? I'm not having much locating anything that appears to be what I need.

    Inspiring
    February 3, 2012

    Not sure what you searched on but Google shows me all sorts of possible solutions when I submitted "javascript change form action".

    Having said that, there may still be rare occasions where your users have disabled js.  You might want to apply the same logic in your coldfusion code as well.