Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Preventing duplicate data in form field submissions...

Posted on 2004-04-29
7
Medium Priority
?
390 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 1000 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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
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 1000 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

877 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