Skip to main content
Participant
July 13, 2011
Question

Re-direct Form based on CFSelect Selection

  • July 13, 2011
  • 1 reply
  • 481 views

Hi,

I'm new to CF, so apollogies if this is a stupid question. It seems like it should be easy, but I can't seem to get it working.

I have a form with a <cfselect> in it. When the form is submitted, I want to re-direct to another page. The page will differ depending on the user's selection in the <cfselect>. I can't seem to pass the user's selection into the form's action method.

Here's some code example which might help illustrate what I mean:

<cfform action="??WhatGoesHere??" method="post" name="frmSelectName" target="_blank">

<cfselect id="selectNamet" name="selectNamet">

<option value="0">John</option>

<option value="1">Paul</option>

</cfselect>

<input type="submit" name="Submit" value="Submit">

</cfform>

Any help would be great!

Thanks!

    This topic has been closed for replies.

    1 reply

    Inspiring
    July 13, 2011

    I would do something like this:

    <cfform action="redirect.cfm" method="post" name="frmSelectName" target="_blank">

    <cfselect id="selectNamet" name="selectNamet">

    <option value="john.cfm">John</option>

    <option value="paul.cfm">Paul</option>

    </cfselect>

    redirect.cfm would have

    <cflocation url = "#form.selectNamet#">

    peadar_cfAuthor
    Participant
    July 13, 2011

    Thanks Dan, that worked

    However, I had simplified my problem for the purpose of asking the question and I'm not sure that this solution will work for my bigger problem. So I'll try explain the bigger issue.

    The existing form, when submitted, generated an Excel report. The code for generating this excel report was contained in a variable called #CGI.SCRIPT_NAME#     (The code for generating the excel was not written by me, and I don't know anything about it other than that is how it's accessed).

    So the original form looked like this:

    <cfform name="form1" action="#CGI.SCRIPT_NAME#" method="post">

    **Some form fields here**

    <input type="submit" name="Submit" value="Submit">

    </cfform>

    However now I need to add in a select option which allows the user to either call the excel script using #CGI.SCRIPT_NAME# variable, or get redirected to another .cfm page.

    Probably should have asked this straight away, but I was hoping I could solve the rest myself....unfortunatly no such luck!

    Thanks again for any help!

    Inspiring
    July 13, 2011

    Your high level logic would resemble this:

    if the form was submitted

    common code for form submission

    if excel

    code for excel

    else

    redirect

    else

    present the form

    For the select, keep it simple.  Offer choices of excel or something else.