Auto-submit hidden form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • golddigger50
    New Member
    • Mar 2007
    • 10

    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...



    Code:
     
    <form method="post" name="form1" action="<cfoutput>#CurrentPage#</cfoutput>">
    <input type="hidden" name="Maildate" value="1"> 
    <input type="hidden" name="MM_UpdateRecord" value="form1">
    <input type="hidden" name="ID" value="<cfoutput>#Recordset1.ID#</cfoutput>">
    </form>
     
    <script>
    document.form1.submit();
    </script>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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.

    Comment

    • golddigger50
      New Member
      • Mar 2007
      • 10

      #3
      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.

      Comment

      • mohsenhosseini
        New Member
        • Mar 2007
        • 28

        #4
        hi dear
        you can use query string. like it:

        <form action="?sendSt at=sent">

        best regards.

        mh

        Comment

        • golddigger50
          New Member
          • Mar 2007
          • 10

          #5
          Mohsenhosseini,

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

          action="?sendSt at=sent">

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

          Golddigger

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            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:
            Code:
            <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.
            Last edited by acoder; Apr 2 '12, 01:02 PM.

            Comment

            • mohsenhosseini
              New Member
              • Mar 2007
              • 28

              #7
              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.

              Code:
              <script language="javascript">
              function writeCookie(name, value, hours)
              {
                var expire = "";
                if(hours != null)
                {
                  expire = new Date((new Date()).getTime() + hours * 3600000);
                  expire = "; expires=" + expire.toGMTString();
                }
                document.cookie = name + "=" + escape(value) + expire;
              }
              
              function readCookie(name)
              {
                var cookieValue = "";
                var search = name + "=";
                if(document.cookie.length > 0)
                { 
                  offset = document.cookie.indexOf(search);
                  if (offset != -1)
                  { 
                    offset += search.length;
                    end = document.cookie.indexOf(";", offset);
                    if (end == -1) end = document.cookie.length;
                    cookieValue = unescape(document.cookie.substring(offset, end))
                  }
                }
                return cookieValue;
              }
              
              
              function submitMyFrm()
              {
              	if( readCookie('frmSent')!='sent' )
              	{
              		writeCookie('frmSent', 'sent', 1);
              		//alert('going to submit');
              		document.getElementById('myFrm').submit();
              	}else
              		{
              			//alert('myFrm sent last time');
              			return false;
              		}	
              }
              </script>
              <form action="" id="myFrm">
              	<input type="hidden" name="name" id="name" value="Mohsen" />
              	<input type="hidden" name="family" id="family" value="Hosseini" />
              </form>
              <script language="javascript">
              submitMyFrm();
              </script>
              best regards.
              MH
              Last edited by acoder; Apr 2 '12, 01:02 PM.

              Comment

              • golddigger50
                New Member
                • Mar 2007
                • 10

                #8
                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.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  Post the code that you have so far.

                  Comment

                  • golddigger50
                    New Member
                    • Mar 2007
                    • 10

                    #10
                    Code:
                    <cfparam name="SESSION.UserID" default="#SESSION.UserID#">
                    <cfset CurrentPage=GetFileFromPath(GetTemplatePath())>
                    <cfif IsDefined("FORM.MM_UpdateRecord") AND FORM.MM_UpdateRecord EQ "form1">
                      <cfquery datasource="website_users">
                      UPDATE #ExpandPath ("/Mailbox\Database\website_users.mail")# SET Confirmed=
                      <cfif IsDefined("FORM.Maildate")>
                        Yes
                        <cfelse>
                        No
                      </cfif>
                      WHERE ID=#FORM.ID# 
                      </cfquery>
                    </cfif>
                    <cfquery name="Recordset1" datasource="websiteusers">
                    SELECT * FROM #ExpandPath ("/Mailbox\Database\website_users.mail")# WHERE UserID = #Session.MM_UserID# 
                    ORDER BY ID DESC 
                    </cfquery>
                    <?xml version="1.0" encoding="iso-8859-1"?>
                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <html xmlns="http://www.w3.org/1999/xhtml">
                    <head>
                    <title>mailed confirmation</title>
                    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                    
                    </head>
                    
                    
                    <cfinclude template="/Mailbox/Includes/NavagationHeader.cfm">
                    <p><font size="6">Confirmed</font></p>
                    
                    
                    <p>&nbsp;</p>
                      
                    
                    
                        
                    
                    <p>&nbsp;</p>
                      
                        
                    <cfparam name="Mail.UserID" default="Mail.UserID">
                        
                    <form method="post" name="form1" action="<cfoutput>#CurrentPage#</cfoutput>">
                      <input type="hidden" name="Maildate" value="1">
                      <input type="hidden" name="MM_UpdateRecord" value="form1">
                      <input type="hidden" name="ID" value="<cfoutput>#Recordset1.ID#</cfoutput>">
                    </form>
                    
                    <script>
                    document.form1.submit();
                    </script>
                    Last edited by AricC; Mar 22 '07, 01:02 AM. Reason: Added Code Tags

                    Comment

                    • AricC
                      Recognized Expert Top Contributor
                      • Oct 2006
                      • 1885

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

                      Aric

                      Comment

                      • golddigger50
                        New Member
                        • Mar 2007
                        • 10

                        #12
                        No Problem
                        Thanks anyway.


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

                        Aric

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          Originally posted by golddigger50
                          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.

                          Comment

                          • golddigger50
                            New Member
                            • Mar 2007
                            • 10

                            #14
                            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

                            Originally posted by acoder
                            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.

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              Ok, I've moved it to the Coldfusion forum.

                              Comment

                              Working...