Support

Home Forums Event Espresso Premium Unique emails upon registration

Unique emails upon registration

Posted: June 14, 2018 at 8:03 am

Viewing 8 reply threads


deon@dieselbrook.co.za

June 14, 2018 at 8:03 am

Hi,

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:

jQuery(document).ready(function($){
	$('#spco-go-to-step-payment_options-submit').on('click',function(e){
		
		
		e.preventDefault();
		e.stopPropagation();
		
		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
		
		$.ajax(
		{
			url : postdetails.ajax_url,
			type : 'post',
			data : {
				action : 'my_action',
				user_email : email,
				event_id : event
			},
			success : function( response ) {
				if (response == 'false')
				{
					$('#ee-spco-attendee_information-reg-step-form').submit();	
				}
				else
				{
					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 years, 5 months ago by Tony. Reason: Code formatting


Tony

  • Support Staff

June 14, 2018 at 9:09 am

Hi there,

I tested your code locally and didn’t run into a problem: http://take.ms/YzEeE

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?


deon@dieselbrook.co.za

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 http://pia.dieselbrook.co.za/events/gerald-steyn-leadership-and-communication/, or any event on that site.


Tony

  • Support Staff

June 15, 2018 at 3:36 am

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


deon@dieselbrook.co.za

June 15, 2018 at 4:48 am

no, it goes through to the payment section.


Josh

  • 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 added your custom code into a plugin on a dev site and found it works as expected.


deon@dieselbrook.co.za

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.


Tony

  • 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.


Josh

  • Support Staff

August 9, 2018 at 2:51 pm

One potential gotcha to be aware of is the script loading order. For example in the above example code you have this:

wp_enqueue_script('ajaxcalls', get_stylesheet_directory_uri().'/js/ajax-registration.js');

Since the script depends on the jQuery library you’ll need to make sure it’s loaded after the jQuery library is loaded onto the page, so you change it to:

wp_enqueue_script(
  'ajaxcalls', 
  get_stylesheet_directory_uri().'/js/ajax-registration.js', 
  false, 
  array('jquery')
);

which tells WordPress to load the custom script after the jQuery library is loaded. Even better, you can load the script after the closing body tag:

wp_enqueue_script(
  'ajaxcalls', 
  get_stylesheet_directory_uri().'/js/ajax-registration.js', 
  false, 
  array('jquery'), 
  true
);
Viewing 8 reply threads

The support post ‘Unique emails upon registration’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso