Solved

Preventing duplicate data in form field submissions...

Posted on 2004-04-29
7
386 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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
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

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.

Question has a verified solution.

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

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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