Avatar of trifecta2k
trifecta2k
 asked on

Jquery AJAX Form Submission/Coldfusion

I have a question about this example:
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/

I am using coldfusion and jquery to have someone fill out the form, validate the name and email address and then insert it into my database. However, I would also like to check the database to make sure that I don't get duplicate email addresses.  How would I go about doing that?    

I am using the same code as shown on that website.  The only difference is that I don't have a return phone field.  I only have name and email address.  
JavaScriptColdFusion Language

Avatar of undefined
Last Comment
trifecta2k

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
McNetic

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
trifecta2k

ASKER
I really like the 2nd option...but what do you mean by have the server return a http error on a duplicate email?  

Currently I am trying to use a simple query to tell if the email address exists:
<cfquery name="check" datasource="lbdb_">
Select * from tbl_member
where member_email = '#url.email#'
</cfquery>

<cfif check.recordCount eq 0>
    query to insert into database and a message to the user
</cfif>

What would I have to do to get your 2nd option to work?  

Thanks for the help.  
SOLUTION
McNetic

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
trifecta2k

ASKER
Sorry for the delayed response...my day got cut short yesterday.  

I tried using cfheader and it shows the error when I use firebug, but it doesn't actually fire off the error function I defined.  I've attached a snippet of the code, maybe I'm doing something wrong.

Here is main part of my js file
$.ajax({
      type: "POST",
      url: "addMember.cfm?" + dataString,
      data: dataString,
      success: function(result) {
        $('#contact_form').html(result);
      }
	  error: function() {
		alert('hello'); 
	  }
     });

Open in new window


Here is my coldfusion file

<cfset cDate = dateformat(now(), 'mm/dd/yyyy')>
<cfquery name="check" datasource="lbdb_">
Select * from tbl_member
where member_email = '#url.email#'
</cfquery>

<cfif check.recordCount eq 0>
    <cfquery name="addMember" datasource="lbdb_">
        insert into tbl_member (member_name, member_email, member_date)
        values ('#url.name#', '#url.email#', #createODBCDate(cdate)#)
    </cfquery>
    <div id="message">Thank you for subscribing</div>
<cfelse>
    <cfheader statuscode="400" statustext="Bad Request" />
    <cfabort />
</cfif>

Open in new window

SOLUTION
McNetic

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
trifecta2k

ASKER
Thanks for the help.  I got it to work!
Your help has saved me hundreds of hours of internet surfing.
fblack61