Question

I'm running the following form inside abc.cfm.

// Parameters Defined

     <cfparam name="startdate" default="#DateFormat(dateAdd('d',-40,now()), 'yyyy-mm-dd')#">
<cfparam name="enddate" default="#DateFormat(dateAdd('d',-1,now()), 'yyyy-mm-dd')#">






     <cfform format="HTML" action="datedownload.cfm" method="get" >


    <cfformgroup type="horizontal">

      <cfinput type="dateField" name="startdate"  width="100" value="#startdate#">
      <cfinput type="dateField" name="enddate"  width="100" value="#enddate#">
      <cfinput name="submitApply" type="submit" value = "Apply">

        <cfinput type="button" name="download" value="Download" onclick="window.location.href='datedownload.cfm?startdate=#form.startdate#&enddate=#form.enddate#path=http://abc.xyz.com/username/July30/datedownload.cfm'"> 




        </cfformgroup>



        </cfform>

Everything is printing fine with the following code in datedownload.cfm

Startdate: <cfdump var = "#startdate#">
End Date :<cfdump var = "#enddate#">

Except that, the Enddate is printing full path along with it as follows:

Startdate: 2013-06-20 End Date : 2013-07-29path=http://abc.xyz.com/username/July30/datedownload.cfm 

How can I remove the stuff starting from path?

Was it helpful?

Solution

If I am reading this correctly, you are getting an error that startdate and enddate are not defined in the form scope when you try to load download.cfm. Since you are passing those variables to download.cfm as part of a query string (by submitting the form using GET), they would not be present in the form scope.

I can think of 2 quick and easy solutions:

First, you can change your reference to form.startdate and form.enddate to url.formdate and url.enddate respectively. Variables passed in as part of the query string (like when you do a GET) become part of the url scope, not the form scope (liek when you do a POST).

Second, you can param the variables like this in download.cfm:

<cfparam name="url.startdate" default="#DateFormat(dateAdd('d',-40,now()), 'yyyy-mm-dd')#">
<cfparam name="url.enddate" default="#DateFormat(dateAdd('d',-1,now()), 'yyyy-mm-dd')#">
<cfparam name="form.startdate" default="#url.startdate#">
<cfparam name="form.enddate" default="#url.enddate#">

This will first param the values in the url scope to the same values you have in the page that displays the form, then it will param the same variable names in the form scope to the same value of the same variable names in the URL scope.

OTHER TIPS

Use an ampersand before enddate instead of the question mark and add an ampersand before the path variable

window.location.href='Download.cfm?startdate=#form.startdate#&enddate=#form.enddate#&path=http://abc.xyz.com/<username>/Testing/Testing/Download.cfm'

The simplest way to solve your problem is to get rid of the 2nd button. It is not necessary and will confuse not only you, but your users. Since your form method is "get" the two formfields will be part of the url scope which seems to be what you want.

Also, where are the form variables coming from in the value attributes of your two inputs?

What's wrong with using a form post? That's the way I prefer to do it. I also test the request type (POST versus GET) to ensure that the download file isn't bookmarkable.

You'll need to use javascript to get the dates in the web-based form, not ColdFusion. (The user will also need to have javascript enabled to use the form to use location.href.)

Give your form fields matching IDs and try the following:

window.location.href='Download.cfm?startdate='+ document.getElementById('startdate').value +'&enddate='+ document.getElementById('enddate').value +'&path=http://abc.xyz.com/<username>/Testing/Testing/Download.cfm';

I'd recommend not using CFForm tags since they require the the /CFIDE/ directory and is currently recommended to be blocked:

Make sure you perform date validation on the server-side. If you need client-side date validation, you can use HTML5 DOCType and the attributes type="date" & required or consider using the jQuery Validation plugin (preferable to CFForm validation).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top