Solved

Preventing duplicate data in form field submissions...

Posted on 2004-04-29
7
385 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Time Sheet Help 6 57
Web site hosting:  Determining the geographic coordinates of visitors to a web site? Their IP Addresses? 11 115
PHP Register global 21 87
System Analysis 5 58
This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

778 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