Solved

Preventing duplicate data in form field submissions...

Posted on 2004-04-29
7
383 Views
Last Modified: 2013-12-24
Hi,

I need to prevent people from submitting the same information in a form field. Here's what I mean:

In form one the person is asked for this info:

First Name:

Last Name:

Email Address:

and in the second part of the system they are asked to refer three for their friends to us by providing the following info..

First Friend's name:

First Friend's email:

Second Friend's name:

Second Friend's email:

Third Friend's name:

Third Friend's email:

How can I prevent my site users from entering something like this for all the form fields?

First Name: ldjfawoejfw

Last Name: ldjfawoejfw

Email address: I need to make sure that the email address is a valid email

The same for the other form fields..

Thanks for your help with this…

Sincerely,
Brandon
0
Comment
Question by:brandonpowell
7 Comments
 
LVL 3

Expert Comment

by:mvwmail
ID: 10952997
The validation of the email address is easy enough.. make sure you are using <CFFORM> as opposed to a nromal email form and use something along these line (Assume Coldfusion MX)

<CFINPUT  TYPE="text"
                NAME="email_address"
                VALIDATE="regular_expression"
                PATTERN =" [A-Za-z0-9_]+@[A-Za-z0-9_]+\.[A-Za-z]+"
                MESSAGE="Please enter Valid Email address">

The entry in this case must contain alphanumerics, or the underscore followed by an @ followed by alphanumercia and then a full stop and then alpha numerics again. It only checks the structure of course not the validity
0
 
LVL 3

Expert Comment

by:mvwmail
ID: 10953024
With regards to actually checking a name, you have a trickier task, as there are no rules.. you could setup expressions checking for unlikely strings of characters in names, but you would find it tricky, and with regards to duplicate entries, what if you just happen to have someone sign up with 2 friends called John John and so on.... just go with checking the email address. methinks, two many rules, means to many chances of error
0
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 250 total points
ID: 10953338
No I would recommend AGAINST cfform.  Even if you want to have javascript do your email validation you can call the function yourself BUT using cfform is a BAD idea as it will lead to problems later on if you need to do anything else on your own in javascript.

Also the cfform validation does one error at a time.  It is better to have one function that catches and displays all errors at once.


So you can either check in javascript or COld Fusion.

If you want to run the checks in cold fusion you could do something like this  to verify that a name was not duplicated:

<cfif Form.Friend2name EQ Form.Friend3name>
   <cfset ErrorMessage = "Friend 2 and 3 are duplicates">
</cfif>

If you have multiple entries like 10 or even some huge number then you can do :

<cfset friendlist = "">
<cfloop index="n" from="2" to="10">
   <cfif ListFindNoCase(friendlist, Form['friend' & n])>
      <cfset ErrorMessage = ErrorMessage  & "You have already entered this name">
  <cfelse>
       <cfset friendlist = ListAppend(freindlist,  Form['friend' & n])>
   </cfif>
</cfloop>

For validating emails I would use something like this :
<cfloop index="n" from="2" to="10">
<cfset IsValid = REFindNoCase('(^[a-z0-9]([._-]*[a-z0-9]+)*[._-]*)+\@[a-z0-9]+([.-]?[a-z0-9]+)*\.[a-z]{2,3}$', Form['Email' & n], 1)>
<cfif NOT IsValid><cfset ErrorMessage =ErrorMessage  & "Please enter a valid email address for friend " & n></cfif></cfloop>

But I would be careful about the duplicate names - just worry about the duplicate emails - not the name since people can have the same name.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 35

Expert Comment

by:mrichmon
ID: 10953372
If you wanted to do the checks in javascript then I would put the check in the onSubmit of the form and return false if you have an error so the form doesn't submit.  There are a lot of free scripts to check email in javascript :

This just looks for a . and a @ :
http://www.codetoad.com/javascript/is_valid_email.asp

Here are some that do more complex checking :
http://www.smartwebby.com/DHTML/email_validation.asp
http://javascript.about.com/library/scripts/blemailvalidate.htm
http://www.javascript-2.com/email-validation.html
0
 
LVL 6

Accepted Solution

by:
usankar earned 250 total points
ID: 10955667
Use javascript
<input type="text" name="firstfriendname">
<input type="text" name="secondfriendname">
<input type="text" name="thirdfriendname">

on form submit
use javascript function
if (firstfriendname.value == secondfriendname.value)
{
  alert(error message);
}
0
 
LVL 17

Expert Comment

by:anandkp
ID: 10957415
yes i wld recommend going along with custom javascript to chk for similar names & validity of email entries

PS : dont forget to have the CF server checks as well ....
0
 

Author Comment

by:brandonpowell
ID: 10958866
Thank you all so very much for all your help with this, and mrichmon you
are right, it is not a good idea to worry about names because I know three
people named John.

Thanks again!

Sincerely,
Brandon
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now