469,926 Members | 1,512 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

JavaScript for time delay onClick goto URL for Form submission

1
I am working in Dreamweaver 8, and I have created a simple form: http://www.realmofmystery.com/app.html

This is a free website I am doing for some friends, so nothing fancy. And, I learned web design before all the CGI and PHP stuff got big, so I prefer to do things simply.

The form worked fine, emails the results like perfect, but it refused to redirect the page to the confirmation. I thought I could add an onClick to the submit button, but this cancels out the form processing.

So, I called my hosting people, they told me to redirect the form action from a mailto, to the gdform.asp file on the server. I did this, and I keep getting errors now. It refuses to work. They are no help, they say I made a mistake scripting, only I didn't script anything!!! I am just using their script. So, I think this could be solved with a simple piece of JavaScript, problem is, I don't know enough about JavaScript to write my own script, but I am assuming the onClick would work if there was also a time delay written into the script that gave the form enough time to submit before redirecting to the confirmation page.

Does anyone have a script to delay the onClick event so I can bypass this?

If you need any extra info, let me know. Also, here is the code contained in my gdform.asp:

Expand|Select|Wrap|Line Numbers
  1. <%
  2.  
  3. Dim landing_page, host_url
  4. Dim fso, outfile, filename, dirname, myFolder
  5. Dim req_method, key, value
  6. Dim bErr, errStr, bEmpty
  7. On Error resume next
  8. bErr = false
  9. bEmpty = true
  10. errStr = ""
  11. Set fso = Server.CreateObject("Scripting.FileSystemObject")
  12. host_url = Request.ServerVariables("HTTP_HOST")
  13. req_method = Request.ServerVariables("REQUEST_METHOD")
  14. dtNow = Now()
  15. filename = Server.MapPath("\ssfm")
  16. dirname = filename
  17. filename = filename & "\gdform_" & DatePart("M", dtNow) & DatePart("D", dtNow) & DatePart("YYYY", dtNow) & DatePart("N", dtNow) & DatePart("S", dtNow)
  18.  
  19. Function FormatVariableLine(byval var_name, byVal var_value)
  20.     Dim tmpStr
  21.     tmpStr = tmpStr & "<GDFORM_VARIABLE NAME=" & var_name & " START>" & vbCRLF
  22.     tmpStr = tmpStr & var_value & vbCRLF
  23.     tmpStr = tmpStr & "<GDFORM_VARIABLE NAME=" & var_name & " END>"
  24.     FormatVariableLine = tmpStr
  25. end function
  26.  
  27. Sub OutputLine(byVal line)
  28.    outfile.WriteLine(line)
  29. end sub
  30.  
  31. if err.number = 0 then
  32.     Set outfile = fso.CreateTextFile(filename, true, false)
  33.     if err.number <> 0 then
  34.             bErr = true
  35.             errStr = "Error creating file! Directory may not be writable or may not exist.<br>Unable to process request."
  36.     else
  37.         if(req_method = "GET") then
  38.             for each Item in request.QueryString
  39.                 if item <> "" then
  40.                     bEmpty = false
  41.                     key = item
  42.                     value = Request.QueryString(item)
  43.                     if(lcase(key) = "redirect") then
  44.                         landing_page = value
  45.                     else
  46.                         line = FormatVariableLine(key, value)
  47.                         Call OutputLine(line)
  48.                     end if
  49.                 end if    
  50.             next
  51.         elseif (req_method = "POST") then
  52.             for each Item in request.form
  53.                 if item <> "" then
  54.                     bEmpty = false
  55.                     key = item
  56.                     value = Request.form(item)
  57.                     if(lcase(key) = "redirect") then
  58.                         landing_page = value
  59.                     else
  60.                         line = FormatVariableLine(key, value)
  61.                         Call OutputLine(line)
  62.                     end if
  63.                 end if    
  64.             next
  65.         end if
  66.         outfile.close
  67.     end if    
  68.     if(bEmpty = true) AND errStr = "" then
  69.         bErr = true
  70.         errStr = errStr & "<br>No variables sent to form! Unable to process request."
  71.     end if
  72.     if(bErr = false) then    
  73.         if (landing_page <> "") then
  74.             response.Redirect "http://" & host_url & "/" & landing_page
  75.         else
  76.             response.Redirect "http://" & host_url    
  77.         end if
  78.     else
  79.         Response.Write errStr
  80.     end if    
  81.     set fso = nothing
  82. else
  83.   Response.Write " An Error Occurred creating mail message. Unable to process form request at this time."
  84. end if
  85. %>
  86.  
When I first changed the form to direct here, I got the first error it mentions, then when I removed the JavaScript to validate the form on submission, I started getting the second error.

Thanks in advance!
Mar 30 '08 #1
2 4798
acoder
16,027 Expert Mod 8TB
This seems like an ASP problem rather than a JavaScript one. I'll move this to the ASP forum.

Have you made sure the form field names match those required by the script?
Apr 1 '08 #2
pronerd
392 Expert 256MB
I am assuming the onClick would work if there was also a time delay written into the script that gave the form enough time to submit before redirecting to the confirmation page.
That would not be a good solution since the user would see the confirmation page, even if an error occurred and their submition did not go though. You really want your server side logic to process the request, then if the request was successfully processed forward them to the confirmation page. Otherwise you want to return an error so they know the request did not go though.

Also, as soon as you submit a request the current page stops executing, so it can not then submitted a second request later. So the only way for what you describe to work would be for the first request to be submitted via AJAX, and then submit the second request to the confirmation page.
Apr 1 '08 #3

Post your reply

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

By using this site, you agree to our Privacy Policy and Terms of Use.