-1

I am attempting to try to add a value of a variable to the end of a URL in a confirmation page after a form is submitted, in ColdFusion. I am able to add the variable with a typical link:

<a href="confirmOrder-solar.cfm?provider=#provider#">

But if I attempt to do the same thing in the form action the value does not show up in the URL:

            <cfif getOffer.RecordCount GT 0>

        <form method="post" action="confirmOrder-solar.cfm?provider=#provider#" id="signupForm">

        <p class="red small">Fields marked with a * are required.</p>
        <div class="panelheader">Your Selected Plan</div>
        <div class="panelcontent">
            <cfoutput query="getOffer">
            <table width="100%" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td class="formfieldlabel" width="180">Rate:</td>
                <td class="normal" style="vertical-align:middle;">#rate#&cent; per kWh</td>
            </tr>
            <tr>
                <td class="formfieldlabel">Term:</td>
                <td class="normal" style="vertical-align:middle;">#term# Months</td>
            </tr>
            <tr>
                <td class="formfieldlabel">Plan Type:</td>
                <td class="normal" style="vertical-align:middle;">Fixed-Rate Plan</td>
            </tr>
            <tr>
                <td class="formfieldlabel">Documents:</td>
                <td class="normal" style="vertical-align:middle;">
                    <cfif offerType EQ "residential">
                        <cfswitch expression="#cancelTerms#">
                            <cfcase value="5mo">&##8226; <a href="../assets/docs/#getProvider.cancelDoc_5mo#" target="_blank">Terms & Conditions</a></cfcase>
                            <cfcase value="10mo">&##8226; <a href="../assets/docs/#getProvider.cancelDoc_10mo#" target="_blank">Terms & Conditions</a></cfcase>
                            <cfcase value="99fl">&##8226; <a href="../assets/docs/#getProvider.cancelDoc_99fl#" target="_blank">Terms & Conditions</a></cfcase>
                            <cfcase value="199fl">&##8226; <a href="../assets/docs/#getProvider.cancelDoc_199fl#" target="_blank">Terms & Conditions</a></cfcase>
                        </cfswitch>
                    <br />
                    <cfelseif offerType EQ "smallcommercial">
                    &##8226; <a href="../assets/docs/smallCommercialContactBlank.pdf" target="_blank">Terms & Conditions</a><br />
                    </cfif>
                    &##8226; <a href="../assets/docs/environmentalDisclosure.pdf" target="_blank">Environmental Disclosure</a><br/>
                    &##8226; <a href="http://testggg.com/wordpress/privacy-policy/" target="_blank">Privacy Policy</a>
                </td>
            </tr>
            <tr>
                <td class="formfieldlabel">Contract Start:</td>
                <td class="normal" style="vertical-align:middle;">
                <cfif Day(now()) LTE 15>
                    <select name="contractStart" id="contractStart">
                        <option value="#Month(DateAdd('m', 0, now()))#/1/#Year(DateAdd('m', 0, now()))#">Immediate</option>
                        <option value="#Month(DateAdd('m', 1, now()))#/1/#Year(DateAdd('m', 1, now()))#">#DateFormat(DateAdd("m", 1, now()), "mmm.")# #Year(DateAdd("m", 1, now()))#</option>
                        <option value="#Month(DateAdd('m', 2, now()))#/1/#Year(DateAdd('m', 2, now()))#">#DateFormat(DateAdd("m", 2, now()), "mmm.")# #Year(DateAdd("m", 2, now()))#</option>
                    </select>
                <cfelse>
                    <select name="contractStart" id="contractStart">
                        <option value="#Month(DateAdd('m', 1, now()))#/1/#Year(DateAdd('m', 1, now()))#">Immediate</option>
                        <option value="#Month(DateAdd('m', 2, now()))#/1/#Year(DateAdd('m', 2, now()))#">#DateFormat(DateAdd("m", 2, now()), "mmm.")# #Year(DateAdd("m", 2, now()))#</option>
                        <option value="#Month(DateAdd('m', 3, now()))#/1/#Year(DateAdd('m', 3, now()))#">#DateFormat(DateAdd("m", 3, now()), "mmm.")# #Year(DateAdd("m", 3, now()))#</option>
                    </select>
                </cfif>
                </td>
            </tr>
            </table>
            </cfoutput>
        </div>
        <cfoutput>
        <div class="panelheader">Personal Information</div>
        <div class="panelcontent">
            <table width="100%" cellpadding="0" cellspacing="0" border="0">
              <!---
              <tr>
                <td class="formfieldlabel" width="180">Company Name:</td>
                <td><input type="text" name="companyName" id="companyName" style="width:240px;"></td>
                <td>&nbsp;</td>
              </tr>
              --->
              <input type="hidden" name="companyName" id="companyName">
              <tr>
                <td class="formfieldlabel" width="180">First Name: <span class="red small">*</span></td>
                <td><input type="text" name="fname" id="fname" style="width:240px;" value="#getCustomer.fname#"></td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td class="formfieldlabel">Last Name: <span class="red small">*</span></td>
                <td><input type="text" name="lname" id="lname" style="width:240px;" value="#getCustomer.lname#"></td>
                <td rowspan="3" width="320" valign="bottom"><cfif getOffer.showReferral EQ "Y"><span class="small"><strong>Were you referred by a friend? Enter their email address here:</strong></span><br /><input type="text" name="referral" id="referral" style="width:240px;"><cfelse><input type="hidden" name="referral" id="referral"></cfif></td>
              </tr>
              <tr>
                <td class="formfieldlabel">Email Address: <span class="red small">*</span></td>
                <td><input type="text" name="email" id="email" style="width:240px;" value="#getCustomer.email#" <cfif session.renewal EQ "Y"></cfif>></td>
              </tr>
              <tr>
                <td class="formfieldlabel">Confirm Email: <span class="red small">*</span></td>
                <td><input type="text" name="email_confirm" id="email_confirm" style="width:240px;" value="#getCustomer.email#" <cfif session.renewal EQ "Y"></cfif>></td>
              </tr>
              <!---
              <tr>
                <td class="formfieldlabel" valign="top">Password:</td>
                <td><input type="password" name="password" id="password" style="width:240px;" <cfif getCustomer.password NEQ "">value="#Decrypt(getCustomer.password, application.encKey, "AES")#"</cfif>><br /><span class="small">If you'd like to establish an account<br />on test, please enter a password.</span></td>
              </tr>
              --->
              <input type="hidden" name="password" id="password" value="" />
            </table>
        </div>
        <div class="panelheader">Service Address</div>
        <div class="panelcontent">
            <table width="100%" cellpadding="0" cellspacing="0" border="0">
              <tr>
                <td class="formfieldlabel" width="180">Address: <span class="red small">*</span></td>
                <td><input type="text" name="serviceAddress1" id="serviceAddress1" style="width:240px;" value="#getCustomer.serviceAddress1#"></td>
              </tr>
              <tr>
                <td class="formfieldlabel">Address (cont.):</td>
                <td><input type="text" name="serviceAddress2" id="serviceAddress2" style="width:240px;" value="#getCustomer.serviceAddress2#"></td>
              </tr>
              <tr>
                <td class="formfieldlabel">City: <span class="red small">*</span></td>
                <td style="vertical-align:middle;">
                    <select name="serviceCitySelect" id="serviceCitySelect" style="width:240px;" onchange="setServiceCity();"><option value=""></option><cfloop list="#getZipCities#" index="city" delimiters=","><option value="#city#" <cfif getCustomer.serviceCity EQ city>selected</cfif>>#city#</option></cfloop><option value="other">Other...</option></select>
                    <br /><input type="text" name="serviceCityText" id="serviceCityText" style="width:240px;" onblur="setServiceCity();" />
                    <input type="hidden" name="serviceCity" id="serviceCity" value="#getCustomer.serviceCity#" />
                </td>
              </tr>
              <tr>
                <td class="formfieldlabel">State: <span class="red small">*</span></td>
                <td style="vertical-align:middle;"><select name="serviceState" id="serviceState" style="width:240px;"><cfloop query="getStates"><option value="#stateCode#" <cfif stateCode EQ application.defaultState OR stateCode EQ getCustomer.serviceState>selected</cfif>>#stateName#</option></cfloop></select></td>
              </tr>
              <tr>
                <td class="formfieldlabel">Zip Code: <span class="red small">*</span></td>
                <td><input type="text" name="dispServiceZip" id="dispServiceZip" value="#session.zipcode#" disabled="disabled" style="width:240px;"></td>
                <input type="hidden" name="serviceZip" id="serviceZip" value="#session.zipcode#">
              </tr>
              <tr>
                <td class="formfieldlabel">Phone: <span class="red small">*</span></td>
                <td><input type="text" name="phone" id="phone" style="width:240px;" value="#getCustomer.phone#"></td>
              </tr>
              <tr>
                <td class="formfieldlabel">Mobile Phone:</td>
                <td><input type="text" name="mobilePhone" id="mobilePhone" style="width:240px;" value="#getCustomer.mobilePhone#"></td>
              </tr>
              <cfif getProvider.useSDI EQ "Y">
              <tr>
                <td class="formfieldlabel">#getProvider.userAcctLabel#: <span class="red small">*</span></td>
                <td>
                    <input type="text" name="sdi1" id="sdi1" value="<cfloop query="getProvider">#sdiPrefix#</cfloop>" maxlength="9" style="width:117px;" readonly="readonly" />
                    <input type="text" name="sdi2" id="sdi2" style="width:110px;" value="#RIGHT(getCustomer.sdi, 8)#" maxlength="8" onBlur="setFullSDI(this.value);"> 
                    <a rel="../assets/images/#getProvider.findAcctNumImage#" href="javascript:return(null);" class="sampleBill" title="How to Locate Your #getProvider.userAcctLabel#:">Where's This?</a><br /><span class="small">Your SDI is tied to your current provider. If the first 9 digits of 
                    your SDI does not match what is shown here, please <a href="../newcustomer.cfm?action=reset">start the process over</a> and choose your correct provider. If you have further problems, please call (855) 322-7448.</span>
                </td>
              </tr>
              <tr>
                <td class="formfieldlabel">Confirm Your #getProvider.userAcctLabel#: <span class="red small">*</span></td>
                <td>
                    <input type="text" name="sdiConfirm" id="sdiConfirm" style="width:240px;" value="#getCustomer.sdi#" maxlength="17"> 
                    <br /><span class="small">Please re-enter your full #getProvider.userAcctLabel# number.</span>
                    <input type="hidden" name="fullSDI" id="fullSDI" value="" />
                </td>
              </tr>
              <cfelse>
              <tr>
                <td class="formfieldlabel">#getProvider.userAcctLabel#: <span class="red small">*</span></td>
                <td>
                    <input type="text" name="sdi1" id="sdi1" value="#getCustomer.sdi#" maxlength="50" style="width:240px;">
                    <input type="hidden" name="sdi2" id="sdi2" value="">
                    <cfif getProvider.findAcctNumImage NEQ "">
                    <a rel="../assets/images/#getProvider.findAcctNumImage#" href="javascript:return(null);" class="sampleBill" title="How to Locate Your #getProvider.userAcctLabel#:">Where's This?</a>
                    </cfif>
                </td>
              </tr>                  
              <tr>
                <td class="formfieldlabel">Confirm Your #getProvider.userAcctLabel#: <span class="red small">*</span></td>
                <td>
                    <input type="text" name="sdiConfirm" id="sdiConfirm" style="width:240px;" value="#getCustomer.sdi#" maxlength="50"> 
                    <br /><span class="small">Please re-enter your full #getProvider.userAcctLabel#.</span>
                    <input type="hidden" name="fullSDI" id="fullSDI" value="" />
                </td>
              </tr>
              </cfif>
            </table>
        </div>
        <div class="panelheader">Billing Address</div>
        <div class="panelcontent">
            <input type="checkbox" name="sameBilling" id="sameBilling" value="Y" /> <label for="sameBilling" style = "color: black" >Same as Service Address</label>
            <table width="100%" cellpadding="0" cellspacing="0" border="0">
              <tr>
                <td class="formfieldlabel" width="180">Address: <span class="red small">*</span></td>
                <td><input type="text" name="billingAddress1" id="billingAddress1" style="width:240px;" value="#getCustomer.billingAddress1#"></td>
              </tr>
              <tr>
                <td class="formfieldlabel">Address (cont.):</td>
                <td><input type="text" name="billingAddress2" id="billingAddress2" style="width:240px;" value="#getCustomer.billingAddress2#"></td>
              </tr>
              <tr>
                <td class="formfieldlabel">City: <span class="red small">*</span></td>
                <td><input type="text" name="billingCity" id="billingCity" style="width:240px;" value="#getCustomer.billingCity#"></td>
              </tr>
              <tr>
                <td class="formfieldlabel">State: <span class="red small">*</span></td>
                <td style="vertical-align:middle;"><select name="billingState" id="billingState" style="width:240px;"><cfloop query="getStates"><option value="#stateCode#" <cfif stateCode EQ application.defaultState OR stateCode EQ getCustomer.billingState>selected</cfif>>#stateName#</option></cfloop></select></td>
              </tr>
              <tr>
                <td class="formfieldlabel">Zip Code: <span class="red small">*</span></td>
                <td><input type="text" name="billingZip" id="billingZip" style="width:240px;" value="#getCustomer.billingZip#"></td>
              </tr>
            </table>
        </div>
        <div style="text-align:center; padding-top:10px;"><input type="submit" value="Continue to Order Review" /></div>
        </cfoutput>
        </form>

        <cfelse>
        <p>&nbsp;</p>
        <div class="errormessage">Something went wrong. We weren't able to find your offer or it is no longer valid. <a href="../newcustomer.cfm">Please go back and search for current offers</a>.</div>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        </cfif>

Is there a simple workaround for this or will it likely take a Javascript solution? Thank you

  • 1
    That should work. How are you accessing the value in your `confirmOrder-solar.cfm` page? Even though you are adding the variable in a `
    ` action you will still need to access it using the `URL` scope, not the `FORM` scope because of how you are passing it.
    – Miguel-F May 15 '17 at 17:32
  • 2
    Also, is there a reason you want to pass it via URL? Would it make it easier if you just pass the provider parameter as a hidden `FORM` field like: ``? – Chester May 15 '17 at 17:34
  • The client wants to see the provider value placed at the end of the URL for analytics purposes. – Tyler Austin May 15 '17 at 17:38
  • can you try: and then in your form action=#temp# – tech2017 May 15 '17 at 17:39
  • Tried that and no luck. What is strange is that typically Notepad++ will change a variable to an orange color. If i just type any variable next to action = it will not change orange. – Tyler Austin May 15 '17 at 17:45
  • 2
  • action="confirmOrder-solar.cfm?provider = #temp# " Tried that but page errors out – Tyler Austin May 15 '17 at 18:11
  • and what is the error? – tech2017 May 15 '17 at 18:13
  • Do you have multiple forms on the page and you have added it to the wrong one? can you write a simple script to demo? – Eccountable May 15 '17 at 18:16
  • It goes to the generic front end page for the site "an error has occured" – Tyler Austin May 15 '17 at 18:16
  • that does not help. hopefully you used the correct variable. #provider# – tech2017 May 15 '17 at 18:20
  • A thing to help with that type of stuff to to wrap in ``. For example: `
    `
    – Chester May 15 '17 at 18:41
  • Tried that wrap but Notepad++ still doesn't recognize #provider# as a variable with that. It only does if I type #provider# but the page redirects to the website error page with that as in action="confirmOrder-solar.cfm?provider = #provider# " – Tyler Austin May 15 '17 at 19:05
  • 3
    I have a feeling you're missing a METHOD attribute. It would be best to post your entire code so that we can see the issue. – Chester May 15 '17 at 20:09
  • 2
    As Chester said: _It would be best to post your entire code so that we can see the issue._ – Miguel-F May 15 '17 at 20:14
  • In addition, help us to help you 1) If you are new to S.O. please read [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). In general, the easier it is for others to test your code, the faster you will get an answer. 2) *RE: It goes to the generic front end page for the site...* Basic troubleshooting 101: Assuming the app resides on a DEV box (it should be) disable error handling so you can actually see error messages. Otherwise, wrap the offending code in a cftry/cfcatch and dump the error in the cfcatch block as Chester suggested. – Leigh May 15 '17 at 23:36
  • Ok I posted the entire code. – Tyler Austin May 16 '17 at 23:17
  • If I use , #provider# is sill not recognized as a variable in the coldfusion file. – Tyler Austin May 16 '17 at 23:19
  • As @techLove suggested, you are missing a `` tag around the `
    ` tag. It is required to ensure the `#provider#` variable is evaluated. *RE: #provider# is sill not recognized* Not recognized how? Are you getting an error or just an empty string? Can you please post that code?
    – Leigh May 17 '17 at 02:36
  • .. or better yet, start with a *very* simple [repro case](http://stackoverflow.com/help/mcve). Only include the minimum necessary to reproduce the issue, like the `
    ` and a single input field. See starter example here: https://trycf.com/gist/094f1dc47d3ceeff12355ca3039c252a/acf2016?theme=monokai
    – Leigh May 17 '17 at 02:49
  • @TylerAustin you have to figure out the error message for debugging. – tech2017 May 17 '17 at 12:33

3 Answers3

0

So this doesn't work for you?

<cfoutput>
     <form action="confirmOrder-solar.cfm?provider=#provider#" >
</cfoutput>
Dakuwan
  • 101
  • 2
0

When you add a URL variable as in

<form action="confirmOrder-solar.cfm?provider=#provider#" method="get">

my experience with ColdFusion is that it strips the URL down to the CFM part (confirmOrder-solar.cfm in your case), appends ? followed a query-string consisting only of the fields in the form. That is, the variable, provider, is ignored.

To achieve the kind of control you want, I would suggest you use Javascript.

BKBK
  • 484
  • 2
  • 9
  • 1
    Based on your experience, if form fields are displayed, why would javascript be better than a hidden form field? – Dan Bracuk May 16 '17 at 11:43
  • It has nothing to do with ColdFusion. The [browser modifies the action](http://stackoverflow.com/questions/1116019/submitting-a-get-form-with-query-string-params-and-hidden-params-disappear#1116026) before the request ever hits CF. A hidden field sounds like the right way to go. – Leigh May 16 '17 at 14:33
  • If I use , #provider# is sill not recognized as a variable in the coldfusion file. – Tyler Austin May 16 '17 at 23:19
  • Not recognized how (empty value, error message, ...)? If you are using method=post, the value will be submitted to the action page as variable name `form.provider`. Obviously wrap it in `cfoutput` tags so the variable is evaluated. – Leigh May 17 '17 at 04:59
  • I stand corrected, Leigh. In fact, looking further into how ColdFusion would handle this, I stumbled upon a possible solution to the puzzle. Albeit a rather curious one. – BKBK Jun 12 '17 at 20:32
  • @Dan Bracuk, hiding the variable isn't a requirement. After all, it is a URL variable, and they don't get more exposed than that. – BKBK Jun 12 '17 at 20:50
0
<cfhttp url="URL_of_domain/testpage.cfm?testVar1=0&testVar2=2"
      method="post">
<cfhttpparam type="formfield" name="x1" value="3" >
<cfhttpparam type="formfield" name="x2" value="4" >
</cfhttp>
<!---
The following variables exist on testpage.cfm:

URL.testVar1
URL.testVar2
FORM.x1
FORM.x2
--->
BKBK
  • 484
  • 2
  • 9