|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionAs with many Internet developers one of the biggest challenges and end user frustrations is the resubmission of data or refresh of a form to post information to a database by an unaware user. Quite often this happens and the user for whatever reason will resubmit or refresh the form and potentially cause chaos with database and/or email submissions. There have been a number of theories presented on this subject, one of the most thorough I’ve read being from Terri Morton. It is not my intent to dispute which of these methods is best but instead to offer an alternative suggestion. HistorySeveral years ago I was challenged by a company which was performing online contest submissions to limit users to one submission per "typed" entry. Additionally they wanted to prevent mass submission companies from flooding their contest with un-prospected candidates and automated entries. After looking at many options, I concluded to create a single use formKey that I could assign and track at the server level for each user every time a form was loaded. Once the form was submitted, I would confirm the existence of the formKey for that form and allow the submission to be processed. At that point, the key would be purged from the system and could no longer be used. Then if the user hits refresh or tries to repost the submission, I could handle the repost in any manner knowing it was a repeat submission. In the cases when a developer is using a multi-step form on a single web form, this process can easily be integrated to maintain each “step” of the form submission process. To expand upon our solution, we’ve integrated it into a VS.NET toolbox server control that can easily be dragged onto a web form and then attached from the code-behind to authenticate the Postback as a single submission making it easy for any developer to integrate. The processThe overall process works as follows:
Because this solution required the use of a database, we also wanted the solution to be scalable to all of our clients and their forms so we updated the database and server control to allow a single control to manage multiple sites and multiple forms on each site. As each site and form is called, the server control registers the web site and web form within the database for future use and tracking. ImplementationAll formKeys are created by the server control and then registered with the database for use on each user requested form. The database consists of three tables: Sites, Forms and FormKeys. Each record within the Sites table maintains a unique hostname where forms are submitted from. Similarly, the Forms table maintains each URL where a form is submitted from. Finally, the FormKeys table tracks each formKey provided by the server control, user’s IP address, and the specific Site and Form in which the key is valid. This is all passed through the stored procedure " Upon each postback the developer calls the Usage of the server control is extremely simple, add the server control to your VS.NET or WebMatrix toolbox and drag the control onto your web form. For best implementation, place it between the <add key="FV_dsn_Server" value="[SERVER NAME OR IP]"/>
<add key="FV_dsn_Database" value="FormManager"/>
<add key="FV_dsn_Username"
value="[USERNAME TO CONNECT TO SQL SERVER]"/>
<add key="FV_dsn_Password"
value="[PASSWORD TO CONNECT TO SQL SERVER]"/>
You can also add the following key When you do a postback just wrap your actual processing within the following code: Dim validator As New TectonicConcepts.FormValidator.FormValidator
If validator.ValidatePostback = True Then
' DO SOMETHING WITH IT HERE
EndIf
If you have a redirect or thank you display message or processing to a next screen, you’ll want to place that outside this code block. For example on our contact form, we do the following: on the first postback we send an email but on subsequent refresh of invalid postbacks we don’t send an email but still display the Thank you panel. Private Sub subForm_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles subForm.Click
If Page.IsValid Then
Dim validator As New _
TectonicConcepts.FormValidator.FormValidator
If validator.ValidatePostback = True Then
Dim mail As New _
TectonicConcepts.TemplateMailer.SendTemplateEmail
mail.SendTemplateMail(_
"Response from the Tectonic Concepts Website", _
"MailTemplates/ContactUsForm.txt", "", _
CMS.Settings.ContactFormSender, _
CMS.Settings.ContactFormRecipient, _
CMS.Settings.ContactFormBccRecipient, _
True, True, True, False, Me.Controls)
End If
ContactForm.Visible = False
Contactus_Intro.Visible = False
ContactUs_ThankYou.Visible = True
EndIf
End Sub
The database setup script and
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||