Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using <cfajaxproxy> to handle form submission?

Guest
Mar 28, 2011 Mar 28, 2011

Coldfusion 9

Im trying to submit a <cfform> to a cfc function without the calling cfm refreshing. The form name is dynamic, and so are the elements within the form. The javascript seems to pass the form as a structure to my cfc, but the <select> value and <textarea> are empty.

------------------------------------------------------------------------------------------------------------------

<cfform id="#randomID#" method="post">

<cfselect name="firstElement">

<option name="firstOption" value='firstValue">first option</option>

<option name="secondOption" value="secondValue">second option</option>

</cfselect>

<cftextarea type="text" name="textAreaOne" rows="5" cols="45"></cftextarea>

<cfinput name="submit" type="button" value="Send" onClick="sendForm('#randomID#')">

</cfform

This is the javascript function that is called by the form:

(The .cfc is formAction.cfc)

------------------------------------------------------------------------------------------------------------------

<cfajaxproxy cfc = "formAction" jsclassname = "cfcClass">

<script type="text/javascript" language="javascript">

function sendForm(formID){

var cfc = new cfcClass();

//This seems to send the form as a structure to my cfc, but the <select> value and <textarea> are empty

var result = cfc.send(formID);

}

This is the CFC:

------------------------------------------------------------------------------------------------------------------

<cfcomponent>
<cffunction name="send" access="remote" returntype="string">
<cfargument name="formResults" type="struct" required="yes">


<cfreturn>
</cffunction>
</cfcomponent>

------------------------------------------------------------------------------------------------------------------

My goal here is to pass the form to the cfc as a structure. I can then loop through the structure and create a list of both the keys and the values. I've also tried to create a string of the values within the javascript prior to the cfc call, but ive run into problems as so much of each form is dynamic.

------------------------------------------------------------------------------------------------------------------

Here is my attempt to extract the form values prior to the cfc call:

function sendForm(formID){

//loop through the form in question

for(i=0; i<document.getElementById(formID).elements.length; i++){

//this works for simple imput elements but not for <select>

var value = document.getElementById(formID).value;

//for <select> ive tried this, but the selectedIndex is always 0:

var value =document.getElementById(formID).selectedIndex;

------------------------------------------------------------------------------------------------------------------

If anyone could help me with either method; send the complete form structure to the cfc, or create a list of values to send to the cfc, i would be a very happy man.

705
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 28, 2011 Mar 28, 2011

There is an easier way to submit to your cfc without the main page refreshing.  Submit your form to a .cfm page in a very small iframe.  Then that .cfm file can send the form as a structure to your cfc.

Translate
LEGEND ,
Mar 28, 2011 Mar 28, 2011
LATEST

There is an easier way to submit to your cfc without the main page refreshing.  Submit your form to a .cfm page in a very small iframe.  Then that .cfm file can send the form as a structure to your cfc.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources