ColdFusion Method

I am sending the value of a variable from the http url to another cfm page, but I'm not sure how to get this value on another page. In php we use $_GET['variable']; I'm not sure what is equivalent to this in ColdFusion.

+3
source share
5 answers

ColdFusion has the ability to access these variables very similar to what you do in PHP:

PHP:

$foo = $_GET['variablename'];
$bar = $_POST['variablename'];

CFScript:

foo = URL['variablename'];
bar = FORM['variablename'];

CFML:

<cfset foo = URL['variablename']>
<cfset bar = FORM['variablename']>

Editing: discussion of case insensitivity of form and workaround

ColdFusion (?) . , , , . , .

:

<form name="main" action="handler.cfm" method="post">
  <input type="text" name="conFUSion" value="abc" />
  <input type="text" name="CONfusion" value="def" />
  <input type="submit" name="Submit" />
</form>

:

Regular Form Scope

gethttprequestdata().content , , :

conFUSion=abc&CONfusion=def&Submit=Submit

ColdFusion , . java.util.HashMap, ColdFusion, :

arFormscope = gethttprequestdata().content.split('&');
cs_form = createobject('java','java.util.HashMap').init();
for( i=1; i<=arraylen(arFormscope); i++ ){
  arElement = arFormscope[i].split('=');
  key = arElement[1];
  value = arElement[2];
  cs_form[key] = value;
}

- cs_form, :

enter image description here

... , :

cs_form['CONfusion']; // def
cs_form['conFUSion']; // abc
cs_form['CONFUSION']; // Error, undefined in java.util.HashMap
+12

#URL.variable# GET. #FORM.variable# POST.

+4

, , , . , test.cfm, :

<cfdump var="#url#">
<cfoutput>
#url['bad bad var name']#<br />
</cfoutput>

:

http://localhost/test.cfm?bad bad var name=foo

"foo" .

:

<cfdump var="#url#">
<cfoutput>
#url.bad bad var name#
</cfoutput>

:

CFML, 3 10. ColdFusion :

.

, URL (), , , - .

+3

You can access them using #url.variable#. For example, in PHP you may have $_GET['id'], and in CF you will have#url.id#

+2
source

I have done this in ColdFusion 7 before.

You can use the value of cgi.query_string to get the query string and then split like this:

httpGetValues = createobject('java','java.util.HashMap').init();

nameValuePairs = cgi.query_string.split('&');
for( i=1; i lte arraylen(nameValuePairs); i = i + 1 ){
    pair= nameValuePairs[i].split('=');
    key = URLDecode(pair[1], "UTF-8");
    value = URLDecode(pair[2], "UTF-8");
    httpGetValues[key] = value;
}

Make sure you decode the values.

0
source

Source: https://habr.com/ru/post/1792872/


All Articles