Home Forums Event Espresso Premium Unique emails upon registration

Unique emails upon registration

Posted: June 14, 2018 at 8:03 am

June 14, 2018 at 8:03 am


I’ve coded an ajax call for checking if the email is already registered for the specific event (and throws a simple javascript alert if already found otherwise continue to payment step). This works fine for data that is pre-filled for logged in users. But if the form is blank on page load and the users fill in their details and submit it throws an error that the fields are required. Why is it not submitting the data that is filled by the user.

My ajax call javascript:

		var email = $('.ee-reg-qstn-email input').val();
		var event =  $('.big-event-title-hdr').attr('id');
		event = event.substr(event.length - 4,4); // this gets the event id from the heading id attribute
			url : postdetails.ajax_url,
			type : 'post',
			data : {
				action : 'my_action',
				user_email : email,
				event_id : event
			success : function( response ) {
				if (response == 'false')
					alert('Your email is already in use for this event. Please try again');
			error : function()
				alert('There was a problem with your registration, please try again.');


My ajax PHP:

add_action('wp_enqueue_scripts', 'pia_ajax_add_scripts');
function pia_ajax_add_scripts()
	wp_enqueue_script('ajaxcalls', get_stylesheet_directory_uri().'/js/ajax-registration.js');
	wp_localize_script( 'ajaxcalls', 'postdetails', array('ajax_url' => admin_url( 'admin-ajax.php' )));

add_action('wp_ajax_my_action', 'my_action_callback');
add_action('wp_ajax_nopriv_my_action', 'my_action_callback');
function my_action_callback() 
    global $wpdb; 
	 $evt_id = $_POST['event_id'];
	$results = $wpdb->get_results('
	SELECT ATT_email FROM wp_esp_attendee_meta 
	INNER JOIN wp_esp_registration ON wp_esp_attendee_meta.ATT_ID = wp_esp_registration.ATT_ID 
	WHERE wp_esp_registration.EVT_ID = '.$evt_id
    $email = $_POST['user_email'];
	$registered = 'false';
	foreach ($results as $result)
		if ($email== $result->ATT_email)
			$registered = 'true';
    echo $registered;
    exit(); // this is required to return a proper result & exit is faster than die();
  • This topic was modified 6 days, 4 hours ago by  Tony. Reason: Code formatting


  • Support Staff

June 14, 2018 at 9:09 am

Hi there,

I tested your code locally and didn’t run into a problem:

I did change this:

event = event.substr(event.length - 4,4);

To be:

event = event.substr(12);

That way it doesn’t matter on the length of your event ID’s like it does with your code but other than that it seems to be working fine.

Is there an event I can view the problem on your site?

June 15, 2018 at 12:15 am

That’s good news I suppose 🙂

I’ve updated the code according to your suggestion, you can try, or any event on that site.


  • Support Staff

June 15, 2018 at 3:36 am

If you remove your custom code from the page, does the same happen?

June 15, 2018 at 4:48 am

no, it goes through to the payment section.


  • Support Staff

June 15, 2018 at 12:47 pm

I tried your site and after I submitted the form it said the First Name was a required value (even though that was filled out). My guess is there’s another script on the page that’s conflicting with the form validation.

As an aside, I loaded up your custom code on a dev site and it works as expected on this event:

June 18, 2018 at 5:26 am

Hi, just to give an update on this. In case it helps someone else who have the same issue.

Feel free to use the code in order to make this work for your site/plugin (accreditation would be nice, but isn’t necessary).

I still have no idea what happened and where the original problem was 🙁 When users were logged in, the registration worked fine. However non logged out users still got the error that data wasn’t submitted correctly.

I disabled all plugins except the event plugin and its addons, and switched to the default (twentysixteen) theme, the problem still persisted…

Then, I updated the event espresso plugin (was a version or two behind), and the problem is resolved, so you can close the ticket.


  • Support Staff

June 18, 2018 at 6:35 am

Thanks for the update and sharing your code.

I’m not sure how updating EE helped with this but I’m glad it’s working either way.

You must be logged in to reply to this support post. Sign In or Register for an Account

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: publish

Updated by  Tony 2 days, 6 hours ago ago

Topic Tags


This topic is: not resolved
Do NOT follow this link or you will be banned from the site!