Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

popup window on form clears data after submit

Posted on 2003-03-31
11
Medium Priority
?
428 Views
Last Modified: 2013-12-24
I have a button on a search filter form that opens a popup window listing several hundred companies for the user to pick from.  The popup window populates a few of the fields on the opener window's form before closing.  A popup is really necessary here instead of a select field because the user's selection is based on several pieces of information about a company.  Error checking is done on the actual submission page, and if errors are encountered, a message is displayed directing the user to go back and correct input.  

Here is the problem: if the button for the popup window is clicked before the form is submitted and the back button is used to return to the form for corrections, all previous input has been cleared.  (If the popup is not used and back is clicked, the previous input is still there.)  CFForm attribute preservedata doesn't work.  Anyone know a way to keep the data on the form if a popup is used?
0
Comment
Question by:dev12
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 10

Expert Comment

by:substand
ID: 8240428
are you using your own coded "back" button?

if so, don't let it "submit" the form, make it's onclick attribute like

onclick="history.go(-1);"

0
 
LVL 11

Expert Comment

by:hart
ID: 8243368
for preventing the main form from loosing data do the following.


Main form with pop up button/image

<form name="mainfrm" method="post" action="somepage.cfm">
form elements
<input type="text" name="somename" value="">

for popping up using image
<A href="javascript:callme()"><img src="image path" alt="Pop Up" border="0"></A>

for popping up using button
<input type="button" name="popme" value="Pop Up" onclick="javascript:callme()">

</form>


now put a anther form after main form(mainfrm)
<form name="subfrm" action="popuppage.cfm" target="popupwinname" method="post">
put hidden fields like
<input type="hidden" name="hiddenname" value="">
</form>

now on the top put this javascript function
<script language="javascript">
function callme()
{
//assign required fields from mainfrm to subfrm. i.e
document.subfrm.hiddenname.value=document.mainfrm.somename.value;
window.open('popuppage.cfm','popupwinname','specify window properties like height,weight etc..')
document.subfrm.submit();
}
</script>


This way only the subfrm will be submitted to the pop up with required values.

And the main frm will remain as it is.

Hope this helps

Regards
Hart
0
 
LVL 11

Expert Comment

by:hart
ID: 8251377
hello did u solve it??

Regards
Hart
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 

Author Comment

by:dev12
ID: 8253032
hart -- Your suggestion did not work.  The data doesn't disappear after the popup is used, but after the form is submitted and then the back button is used to return to the form.  I have no clue what to do.  Using preservedata doesn't work, having the popup reload the input field values as it closes doesn't work.

Anyone who knows anything about this, help!
0
 
LVL 10

Expert Comment

by:substand
ID: 8258105
could you possibly use session vars to keep track of what the form values were, then use like

<cfif isdefined("session.fieldname")>value="#session.fieldname#"</cfif>

on the fields?

0
 
LVL 11

Expert Comment

by:hart
ID: 8259778
from the pop up don't sumbit the page to the main form.

Just assign those values to the main form elements.

i hope we wre both thinking the same..


1. You have a main form.
2. from which for some of the values you pop up a screen and select some values which will be automatically assigned to the main form

for this use window.opener.mainformname.fieldname.value=document.popupformname.fieldname.value and put this code onsubmit of the pop up form.


3. Then You just submit the main form.

Thatz it right..?

Regards
Hart
0
 

Author Comment

by:dev12
ID: 8261063
substand - I can't use the session variables because sometimes the form needs to come up filled out by a query for an existing database entry, sometimes blank for a new database entry.

hart - My popup window doesn't submit to the main form.  We are thinking along the same lines, and the popup simply assigns the values to the correct fields on the main form before it closes.  

This is the problem:  The user clicks on the button to open the popup, chooses something from the popup, and submits the main form.  If there is a data error (incorrect date or something), the submission page will display a message for the user to go back and correct the data.  On clicking the browser's back button, all input that was on the form is now gone.  It's not that the data disappears when the popup closes, but when the back button has to be used to get back to the form after submission.

The only thing I can think of is to do all data validation in javascript so that the back button will never need to be used after form submission.  Any other suggestions?
0
 
LVL 2

Accepted Solution

by:
jalpino earned 300 total points
ID: 8267093
Here is a simple example of how you can 'preserve' the values of your form variables after you submit them using the post method.


<!--- :: FORM PAGE :: myform.cfm --->

<!--- Initialize your form variables --->
<cfparam name="form.fname" default="">
<cfparam name="form.lname" default="">
<cfparam name="form.age" default="0">

<html>
<head>
     <title> My form </title>
</head>
<body>

<!--- Display your form --->
<table cellspacing="0" cellpadding="3" border="0">
<form name="myForm" action="processingpage.cfm" method="post">
<cfoutput>
<tr>
     <td> First Name </td>
     <td> <input type="Text" name="fname" value="#form.fname#"></td>
</tr>
<tr>
     <td> Last Name </td>
     <td> <input type="Text" name="lname" value="#form.lname#"></td>
</tr>
<tr>
     <td> Age </td>
     <td>
          <select name="age">
               <cfloop from="18" to="55" index="i">
               <option value="#i#" <cfif i EQ form.age> selected </cfif>> #i#
               </cfloop>
          </select>
     </td>
</tr>
</cfoutput>
<tr>
     <td colspan=2> <input type="submit" value="Submit"> </td>
</tr>
</form>
</table>

</body>
</html>



<!--- :: Processing Page :: processingpage.cfm --->

<!--- Initialize incoming form variables --->
<cfparam name="form.fname" default="">
<cfparam name="form.lname" default="">
<cfparam name="form.age" default="0">

<html>
<head>
     <title> Sorry </title>
</head>
<body>

Sorry, please return to the form.

<form name="returnForm" action="myform.cfm" method="post">
     <cfoutput>
     <input type="hidden" name="fname" value="#trim(form.fname)#">
     <input type="hidden" name="lname" value="#trim(form.lname)#">
     <input type="hidden" name="age" value="#val(form.age)#">
     </cfoutput>
     
     <input type="submit" value="Click Here to Return to the Form">
</form>

</body>
</html>


Good Luck

Jalpino
0
 
LVL 11

Expert Comment

by:hart
ID: 8267138
ok the only solution that i can think of is to send ll the values submitted back to the same page using hiddenfileds.

and check for existence in the main form and show the value.

i.e
<input type="text" name="somename" <cfif isdefined('hiddenvariablename')>value="#hiddenvariablename#"<cfelse>value=""</cfif>>


or you can put javascript checks before submitting to check for appropraite data to be submitted..

Regards
Hart
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10940985
No comment has been added lately, so it's time to clean up this question.
I will leave the following recommendation in the Cleanup topic area:

Accept jalpino

Please leave any comments here within the next four days.

mrichmon
EE Cleanup Volunteer
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
What You Need to Know when Searching for a Webhost Provider
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question