Wes Loflin
Wes Loflin

Reputation: 27

How can I pass variables from 2 separate forms on one cfm to another cfm in coldfusion?

I have 2 forms on one page that I need to pass to the same page to assemble a pdf. How can I do that? I have tried using a action="post" for one and action="get" for the other, but I can't get that to work. I have tried assigning one form to session variables, but I can't get that either. Any suggestions??

  <form name="formOne" id="formOne" method="post" action="#buildURL('goTothisPage.page')#">
        <input name="name" id="name"  autofocus="true" >
        <input name="address" id="address" >

Upvotes: 2

Views: 264

Answers (2)

Stefan Braun
Stefan Braun

Reputation: 400

If it is required to have two separate forms in your html, it is also possible to forge the form values from one form into the other at the moment of the submit event.

HTML:

<form name="formOne" id="formOne" method="post">
    <input name="name" id="name" type="text" >
    <input name="address" id="addressHidden" type="hidden">
</form>
<form name="formTwo" id="formTwo" method="post">
    <input name="address" id="address" type="text">
    <input name="name" id="nameHidden" type="hidden" >
</form>

Javascript:

$(document).ready(function(){
    $('#formOne').submit(function(event){
        $('#addressHidden').val($('#address').val());
        return true;
    });
    // same for #formTwo
    $('#formTwo').submit(function(event){
        $('#nameHidden').val($('#name').val());
        return true;
    });
});

Upvotes: 0

ChrisG
ChrisG

Reputation: 96

I would try just creating one big form instead of 2 smaller forms if the action is going to be the same and go to the same .cfm page. (Just expand the scope of your tags)

You can also create 2 "Submit" buttons (1 for each form) to make it appear as 2 separate forms, even though the buttons will submit the same form.

Upvotes: 4

Related Questions