473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Auto-submit hidden form

Hello,

I am trying to autosubmit a hidden form.

So far I have...... but it sends me into an infinite loop. Anyone got any ideas. I am such a noob...



Expand|Select|Wrap|Line Numbers
  1.  
  2. <form method="post" name="form1" action="<cfoutput>#CurrentPage#</cfoutput>">
  3. <input type="hidden" name="Maildate" value="1"> 
  4. <input type="hidden" name="MM_UpdateRecord" value="form1">
  5. <input type="hidden" name="ID" value="<cfoutput>#Recordset1.ID#</cfoutput>">
  6. </form>
  7.  
  8. <script>
  9. document.form1.submit();
  10. </script>
  11.  
Mar 15 '07 #1

✓ answered by acoder

By updating, you mean setting confirmed to true/yes/1?

Try this:
Expand|Select|Wrap|Line Numbers
  1. <cfquery datasource="website_users">
  2.   UPDATE #ExpandPath ("/Mailbox\Database\website_users.mail")# SET Confirmed=1
  3.   WHERE ID=#Recordset1.ID# 
  4. </cfquery>

23 20945
acoder
16,027 Expert Mod 8TB
This will send you into an infinite loop because you are submitting to the same page. When that page loads, it submits again and again and again!

To prevent that, pass a variable which should set that you've submitted. If that's not set, submit the form, otherwise do not submit.
Mar 15 '07 #2
Acoder, thank you for your help. I was thinking something along those lines would work, but I am in the early stages of learning java. Could you possible show me an example of how to pass a variable saying that I have submited. Your guidance is greatly appreciated.
Mar 15 '07 #3
hi dear
you can use query string. like it:

<form action="?sendStat=sent">

best regards.

mh
Mar 15 '07 #4
Mohsenhosseini,

Thank you for your concern, but the page is still looping. I changed the form action to:

action="?sendStat=sent">

If I made some obvious mistake please correct me. This is all very new to me and I appreciate your patients.
Thanks

Golddigger
Mar 15 '07 #5
acoder
16,027 Expert Mod 8TB
Keep your action attribute as it is, but add the variable "?sendstat=sent" or "?sent=1" or whatever you choose. You can name it whatever you like, it's up to you as long as you set some variable.

Then, in your server-side code, just check that the variable has not been defined. If it hasn't, then include your auto-submit code. Since you're using Coldfusion, you could try:
Expand|Select|Wrap|Line Numbers
  1. <cfif not isDefined("url.sendStat")> put form submit code here
That's one way - there are other ways including Javascript checking or sending via posted form variable rather than in the URL.
Mar 16 '07 #6
hi dear
you can call me mohsen.

i wrote the code for you i hope it can be usefull for you .
the code tested and work great.

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function writeCookie(name, value, hours)
  3. {
  4.   var expire = "";
  5.   if(hours != null)
  6.   {
  7.     expire = new Date((new Date()).getTime() + hours * 3600000);
  8.     expire = "; expires=" + expire.toGMTString();
  9.   }
  10.   document.cookie = name + "=" + escape(value) + expire;
  11. }
  12.  
  13. function readCookie(name)
  14. {
  15.   var cookieValue = "";
  16.   var search = name + "=";
  17.   if(document.cookie.length > 0)
  18.   { 
  19.     offset = document.cookie.indexOf(search);
  20.     if (offset != -1)
  21.     { 
  22.       offset += search.length;
  23.       end = document.cookie.indexOf(";", offset);
  24.       if (end == -1) end = document.cookie.length;
  25.       cookieValue = unescape(document.cookie.substring(offset, end))
  26.     }
  27.   }
  28.   return cookieValue;
  29. }
  30.  
  31.  
  32. function submitMyFrm()
  33. {
  34.     if( readCookie('frmSent')!='sent' )
  35.     {
  36.         writeCookie('frmSent', 'sent', 1);
  37.         //alert('going to submit');
  38.         document.getElementById('myFrm').submit();
  39.     }else
  40.         {
  41.             //alert('myFrm sent last time');
  42.             return false;
  43.         }    
  44. }
  45. </script>
  46. <form action="" id="myFrm">
  47.     <input type="hidden" name="name" id="name" value="Mohsen" />
  48.     <input type="hidden" name="family" id="family" value="Hosseini" />
  49. </form>
  50. <script language="javascript">
  51. submitMyFrm();
  52. </script>
  53.  
best regards.
MH
Mar 16 '07 #7
Hey,

Sorry I haven't been able to post in a while. Once again I appreciate how helpful you have been. Unfortunately I can not get the page to work properly.

Maybe it would be helpful if I was more clear on my goal. I am trying to update a record in ms access. When the page is loaded a hidden form is submited. The form will add a check to a checkbox(or change the value from a "0" to a "1") in the database.

This is all very new and exciting to me, but at times frustrating. Thanks for help.
Mar 21 '07 #8
acoder
16,027 Expert Mod 8TB
Post the code that you have so far.
Mar 21 '07 #9
Expand|Select|Wrap|Line Numbers
  1. <cfparam name="SESSION.UserID" default="#SESSION.UserID#">
  2. <cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
  3. <cfif IsDefined("FORM.MM_UpdateRecord") AND FORM.MM_UpdateRecord EQ "form1">
  4.   <cfquery datasource="website_users">
  5.   UPDATE #ExpandPath ("/Mailbox\Database\website_users.mail")# SET Confirmed=
  6.   <cfif IsDefined("FORM.Maildate")>
  7.     Yes
  8.     <cfelse>
  9.     No
  10.   </cfif>
  11.   WHERE ID=#FORM.ID# 
  12.   </cfquery>
  13. </cfif>
  14. <cfquery name="Recordset1" datasource="websiteusers">
  15. SELECT * FROM #ExpandPath ("/Mailbox\Database\website_users.mail")# WHERE UserID = #Session.MM_UserID# 
  16. ORDER BY ID DESC 
  17. </cfquery>
  18. <?xml version="1.0" encoding="iso-8859-1"?>
  19. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  20. <html xmlns="http://www.w3.org/1999/xhtml">
  21. <head>
  22. <title>mailed confirmation</title>
  23. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  24.  
  25. </head>
  26.  
  27.  
  28. <cfinclude template="/Mailbox/Includes/NavagationHeader.cfm">
  29. <p><font size="6">Confirmed</font></p>
  30.  
  31.  
  32. <p>&nbsp;</p>
  33.  
  34.  
  35.  
  36.  
  37.  
  38. <p>&nbsp;</p>
  39.  
  40.  
  41. <cfparam name="Mail.UserID" default="Mail.UserID">
  42.  
  43. <form method="post" name="form1" action="<cfoutput>#CurrentPage#</cfoutput>">
  44.   <input type="hidden" name="Maildate" value="1">
  45.   <input type="hidden" name="MM_UpdateRecord" value="form1">
  46.   <input type="hidden" name="ID" value="<cfoutput>#Recordset1.ID#</cfoutput>">
  47. </form>
  48.  
  49. <script>
  50. document.form1.submit();
  51. </script>
  52.  
Mar 21 '07 #10
AricC
1,892 Expert 1GB
Sorry don't know any ColdFusion. ACoder is probably the only one who can help you out with this.

Aric
Mar 22 '07 #11
No Problem
Thanks anyway.


Sorry don't know any ColdFusion. ACoder is probably the only one who can help you out with this.

Aric
Mar 22 '07 #12
acoder
16,027 Expert Mod 8TB
Hey,

Sorry I haven't been able to post in a while. Once again I appreciate how helpful you have been. Unfortunately I can not get the page to work properly.

Maybe it would be helpful if I was more clear on my goal. I am trying to update a record in ms access. When the page is loaded a hidden form is submited. The form will add a check to a checkbox(or change the value from a "0" to a "1") in the database.

This is all very new and exciting to me, but at times frustrating. Thanks for help.
Why not just run the query on page load rather than submitting a hidden form? This would avoid having to submit the form. You know the value that you have to set in the database.

Have you got any problems in your Coldfusion? If you have, I'll move this to the CF forum.
Mar 22 '07 #13
Acoder,

You are welcome to move this thread to the CF forum. I am not sure how to update the record without submiting the form. I would be forever greatful if you would show me. Thanks

golddigger

Why not just run the query on page load rather than submitting a hidden form? This would avoid having to submit the form. You know the value that you have to set in the database.

Have you got any problems in your Coldfusion? If you have, I'll move this to the CF forum.
Mar 22 '07 #14
acoder
16,027 Expert Mod 8TB
Ok, I've moved it to the Coldfusion forum.
Mar 23 '07 #15
acoder
16,027 Expert Mod 8TB
How else are you using this page? In other words, when you access this page, you obviously want it to set a value in the database, so you have tried submitting a form. What behaviour do you require on this page? Would it ever be that when you access this page, you don't want to set that value?
Mar 23 '07 #16
The server behavior, would be to update the record in the database and I would like to update record everytime user accesses this page. Hope this was helpful...




How else are you using this page? In other words, when you access this page, you obviously want it to set a value in the database, so you have tried submitting a form. What behaviour do you require on this page? Would it ever be that when you access this page, you don't want to set that value?
Mar 23 '07 #17
acoder
16,027 Expert Mod 8TB
By updating, you mean setting confirmed to true/yes/1?

Try this:
Expand|Select|Wrap|Line Numbers
  1. <cfquery datasource="website_users">
  2.   UPDATE #ExpandPath ("/Mailbox\Database\website_users.mail")# SET Confirmed=1
  3.   WHERE ID=#Recordset1.ID# 
  4. </cfquery>
Mar 23 '07 #18
This code seems like it should work but I am not getting the record to update to a true value.
Mar 23 '07 #19
acoder
16,027 Expert Mod 8TB
The Recordset1 query should be before this update query.
Mar 24 '07 #20
Acoder,

Thank you for your time and your help. This is the code that worked.


Expand|Select|Wrap|Line Numbers
  1. <cfquery name="Recordset1" datasource="website_users">
  2. SELECT * FROM #ExpandPath ("/Mailbox\Database\website_users.mail")# WHERE UserID = #Session.MM_UserID# 
  3. ORDER BY ID DESC 
  4. </cfquery>
  5.  <cfquery datasource="website_users">
  6.   UPDATE #ExpandPath ("/Mailbox\Database\website_users.mail")# SET Confirmed=1
  7.   WHERE ID=#Recordset1.ID# 
  8.   </cfquery>
  9.  
I was getting errors because I had not deleted the form. After I removed the form there were no errors but the value was not being inserted. I then realized that the <cfif> isdefined ....updateform... that is inserted when dreamweaver updaterecord server behavior is used had not been removed. I removed it and it worked great. I could not have done it without your help Thanks.

Golddigger

The Recordset1 query should be before this update query.
Mar 26 '07 #21
acoder
16,027 Expert Mod 8TB
No problem. You're welcome. Glad you got it working.
Mar 26 '07 #22
Here is a working auto-submit method: when page is loaded, it will the form will be immediately autosubmited (the values can be set with php variables).
Expand|Select|Wrap|Line Numbers
  1. <form action="page.php"  method="post">
  2. <input type="text" name="example1" value="<?php echo $_POST['something1'];?>" />
  3. <input type="text" name="example2" value="ANOTHER_YOUR_VALUE" />
  4. <input type="submit" />
  5. </form>
  6.  
  7. <SCRIPT LANGUAGE="JavaScript">document.forms[0].submit();</SCRIPT>
  8.  
for example, the $_POST['something1'] value is received from the previous real-user submited Form, and this form can add another input with ANOTHER_YOUR_VALUE.

_______________________
Jan 24 '13 #23
acoder
16,027 Expert Mod 8TB
...except that the question was Coldfusion-related :)

Just a note that the script language attribute is deprecated - use, for example,
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
Jan 26 '13 #24

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Manlio Perillo | last post by:
Hi. This post follows "does python have useless destructors". I'm not an expert, so I hope what I will write is meaningfull and clear. Actually in Python there is no possibility to write code...
5
by: Robert Downes | last post by:
I'm using the following in a page that I'm testing in Mozilla: p.actionLinkBlock {border: 1px #000000 dashed; padding: 0.2cm; width: auto} But the dashed border is extending to the right-edge...
20
by: Vijay Kumar R. Zanvar | last post by:
Hello, Unlike register, auto keyword can not be used to declare formal parameter(s). Is there any specific reason for this? Kind regards, Vijay Kumar R. Zanvar
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
5
by: Samuel | last post by:
Hi, I am running into a problem of mixing UICulture = auto and allowing users to select culture using a dropdown list. I am detecting a querystring, "setlang", and when found, setting the...
5
by: maya | last post by:
at work they decided to center divs thus: body {text-align:center} #content {width: 612px; text-align:left; margin: 0 auto 0 auto; } this works fine in IE & FF, EXCEPT in FF it doesn't work if...
13
by: S.Dickson | last post by:
I had an access database that i use as an ordering system. I have a form for entering customer details. When i add a new customer on the form the customer number is an auto number that appears when...
22
by: nospam_news | last post by:
I currently get asked about my usage of "auto". What is it for? The keyword is clearly superflous here. In contrast to the huge majority of C/C++ developers I write definitions very explicitly...
2
by: Piotr K | last post by:
Hi, I've encountered a strange problem with Firefox which I don't have any idea how to resolve. To the point: I've <divelement with a style "height: auto" and I want to retrieve this value...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.