Solved

Preventing duplicate data in form field submissions...

Posted on 2004-04-29
7
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

635 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