|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
||||
|
||||
|
problem passing values through 2 forms
my first form gets a category... the second form displays the ability to enter values in a table where the category is the category previously entered... the input is disabled, but displayed... like so...
<INPUT type="text" name="category2" value="#form.category#" disabled> i used input, not cfinput, because disabled is not supported by cfinput... so i get to the third step (actually inserting the values into the table), and it says no value associated with form.category2... shouldn't the value be the same value that was inserted into form.category? i'm missing something here...
__________________
Reinventing the wheel again |
|
#2
|
|||
|
|||
|
Hello,
firstly disabled *is* supported by cfinput but you have to use the passthrough attribute, remember if using cfinput, you need to use cfform. Secondly from what I interpret your problem to be, (forgive me if i am wrong) is that the form value "form.catergory2" is no longer availible as form variables are not persistant. You need to save the first form variable as a variable with a persistant scope such as request or client, then insert the value "client.catergory2". Tell me if i've got the wrong end of the stick completely and i'll rethink my answer. |
|
#3
|
||||
|
||||
|
Ok, used the passThrough now...
But if I say something like... FIRST FORM--- <cfinput type="text" name="category"> SECOND FORM--- <cfinput type="text" name="category2" value="#form.category#" passThrough="disabled"> then why wouldn't category2 hold the value input into category in the first form? meaning when i try to grab category2 in the third form, why doesn't it equal category? Thanks.... Last edited by mateoc15 : April 15th, 2004 at 05:24 PM. |
|
#4
|
|||
|
|||
|
Keep in mind that not all browsers support "disabled", so your carefully crafted solution could very possibly be sidestepped anyway. I'd avoid it altogether and just use a hidden form field and/or display the data as HTML text instead of trying to use a disabled form field.
|
|
#5
|
||||
|
||||
|
I must really not be understanding...
I have looked up client and request variables in the documentation. How is there a difference in the way that they are assigned? Are they stored in a different location? If I set SOMEVARIABLE = #form.category#, where in the logic should I do it? What about CFAPPLICATION? Can I just use CFSET to set an application variable? TRULY LOST NOW... Thanks |
|
#6
|
|||
|
|||
|
Quote:
The request scope is not persistant in this sense. This is a simple problem and the simple solution is as follows: If one form posts to another form simply refernce the variable on the second form as form.varName or form['varName'], whichever syntax you prefer. If form 1 does not post to form 2, then you need to keep track of the initial form value via a perst.. scope (session, cookie, client). Don't forget to clear it out when you are done using it and always cfparam your values so they always exist when you need them to, then just check for content. HTH, Mike Last edited by mtangorre : April 15th, 2004 at 11:07 PM. |
|
#7
|
|||
|
|||
|
Quote:
|
|
#8
|
||||
|
||||
|
Quote:
If I'm reading you correctly, that's just what I need. Check out the link I supplied earlier... http://cislab2.cbpa.louisville.edu/...chandiseAdd.cfm The first one gets a category (generated from a query), then the fields for that category are input (see second page... try it out). Then the error occurs when the data from the second form (merchandiseAdd2.cfm) is inserted into the table as a new record. Error says that #form.category# does not exist basically. So there's an easier way to do this? What did you mean exactly by that, KITELESS? I have an idea... why don't I just paste the code from EACH of the three... merchandiseAdd.cfm Code:
<CFINCLUDE template="includes/header.cfm"> <CFQUERY datasource="#DataSource#" name="categoryQuery"> SELECT DISTINCT Category FROM Category </CFQUERY> <HTML> <HEAD><LINK rel="stylesheet" href="includes/style.css"></HEAD> <BODY> <CFFORM action="merchandiseAdd2.cfm" method="post"> <CENTER> <SPAN class="title">Select a category to which you wish to add:</SPAN> <BR> <CFSELECT name="category"> <OPTION value="" selected>---------- <CFOUTPUT query="categoryQuery"> <OPTION value="#Category#">#Category# </CFOUTPUT> </CFSELECT> <BR> <INPUT type="submit" value="Add record to this Category"> </CENTER> </CFFORM> </BODY> </HTML> merchandiseAdd2.cfm Code:
<CFINCLUDE template="includes/header.cfm"> <HTML> <HEAD><LINK rel="stylesheet" href="includes/style.css"></HEAD> <BODY> <CFFORM action="merchandiseAdd3.cfm" method="post"> <CENTER> <SPAN class="title">Enter your new record:</SPAN><BR> <CFOUTPUT> Item ID:<CFINPUT type="text" name="itemid" required="yes"> Description:<CFINPUT type="text" name="description" required="yes"> Quantity On Hand:<CFINPUT type="text" name="qoh" required="yes"> <BR> List Price: $<CFINPUT type="text" name="listprice" required="yes"> Category:<CFINPUT type="text" name="category" value="#form.category#" passThrough="disabled"> <BR> <INPUT type="submit" value="Submit New Record to #form.category#"> </CFOUTPUT> </CENTER> </CFFORM> </BODY> </HTML> merchandiseAdd3.cfm Code:
<CFINCLUDE template="includes/header.cfm"> <CFQUERY datasource="#DataSource#" name="existingItemID"> IF #form.itemid# NOT IN(SELECT ItemID FROM Merchandise) INSERT INTO Merchandise (ItemID, Description, QuantityOnHand, ListPrice, Category) VALUES (#form.itemid#, '#form.description#', #form.qoh#, #form.listprice#, '#form.category#') </CFQUERY> <HTML> <HEAD><LINK rel="stylesheet" href="includes/style.css"></HEAD> <BODY> <CFIF existingItemID.getRowCount() IS 0> <CFOUTPUT>Record could not be added. Item ID #form.itemid# already exists in the table.</CFOUTPUT> <CFELSE> <CENTER> <SPAN class="title">Your new record successfully inserted:</SPAN><BR> <TABLE width="700"> <TR> <TH>Item ID</TH> <TH>Description</TH> <TH>Quantity On Hand</TH> <TH>List Price</TH> <TH>Category</TH> </TR> <CFOUTPUT query="merchandiseQuery"> <TR> <TD>#ItemID#</TD> <TD>#Description#</TD> <TD>#QuantityOnHand#</TD> <TD>#LSNumberFormat(ListPrice, "$___,___.__")#</TD> <TD>#Category#</TD> </TR> </CFOUTPUT> </CENTER> </CFIF> </BODY> </HTML> |
|
#9
|
|||
|
|||
|
First, lets back off a second. When it comes to troubleshooting and problem solving, the best thing you can do is strip everything away except for the things that exhibit the problem or error. So lets create 3 very simple pages that should illustrate a solution. From there, you can take what you need to scale it up to your situation.
Code:
Page 1<p> <form action="page2.cfm" method="post"> Form 1 Text: <input type="text" name="form1text"> <input type="submit" value="Go To Page 2"> </form> Code:
Page 2<p> <cfoutput> <form action="page3.cfm" method="post"> Data from form 1: #form.form1text#<br> <input type="hidden" name="form1text" value="#form.form1text#"> Form 2 Text: <input type="text" name="form2text"> <input type="submit" value="Go To Page 3"> </form> </cfoutput> Code:
Page 3<p> <cfdump var="#form#"> This posts the first form to page 2, where that data is placed into a hidden form field. When the form on page 2 posts, it posts the new form 2 data along with the data from form 1 that is now in the hidden form field. As you can see, on page 3 the dump of the form scope shows the data from both forms. |
|
#10
|
||||
|
||||
|
FINALLY, SUCCESS!
I used a hidden field, but I still don't understand why it must be a hidden field rather than using the VALUE from the DISABLED field. If a field is disabled, you apparently cannot get a value from it using form.disabledfieldname |
|
#11
|
|||
|
|||
|
Like I said, I never use disabled fields because they are not uniformly supported, so I have no idea how their data is handled. Stick with what's standard.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > problem passing values through 2 forms |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|