Interrupt sign up

Hi All,

How can I interrupt a sign up and display my own error message using a pro from?

I’d like to check if an email comes from a particular domain and block it if it is.

I’m using the technique from here: https://s2member.com/kb-article/using-the-e-mail-address-as-the-username/

to get the post values and check if they are of a certain email, which works great, but I don’t know how to cancel the sign up with my own error message…

is this possible? and if so how?

I’d like to say thanks for all the previous assistance I’ve got from the community, this is the last step to completing my project, so thanks again guys!

Anybody have any ideas?

cheers

I haven’t seen it done like this. I know you would use JavaScript.

Here is a hack that uses JavaScript to get the username from the email address. Maybe that’s a start for something that’ll be checking the email address’ domain name. https://s2member.com/kb-article/using-the-e-mail-address-as-the-username/

I hope that helps. :slight_smile:

Hi I’ve already succesfully done the email valiadation using only PHP.

The link you pasted is the same as me lol :slight_smile:

What I need to know is which hook (there miust be one) which I can use to deny or allow registration, and if there is a hook to add message dialogs to the reg form.

Thanks

If you use a WP hook, that’d be on the server side. So on validation of the email, if not valid, you can can send him back to the form page with a message at the top or something, asking him to change it.

For this to happen dynamically on the page with the form before he submits, then you need to use javascript. I don’t have a code for you to do this, sorry. The emai field has an ID that you can use to select/target it with your JS.

yeah I’d like to do it server side if possible so nobody can bypass it by disabling javascript…

Then you already did that, right? You said you did the validation with PHP.

I’m not sure I understand what else you need then. :slight_smile:

Hi,

Thanks for trying to help, let me explain better.

The email validation is simple but the form still performs the registration as I don’t know how to cancel the registration.

I’ve added some sudo code below, I can check the condition but I can’t prevent the registration

function update_post_vars_for_registration()
{
	$email = get_email();
	if(email_is_valid($email)){
		//continue registration
	}else{
		//stop registration
		//what do i put here???		
	}
{
add_action('init', 'update_post_vars_for_registration', 1);

If i put an exit in the stop registration condition it won’t register but I need a way to prevent resitration and return to the form and display a message.

hope that makes sense?

I see. I haven’t done this hack myself, but it should be possible.

I seemed to remember someone doing something similar before, so I searched the forums and found this one: https://www.s2member.com/forums/topic/hidden-fields-and-validation-in-pro-forms/index.html#post-8451

Maybe it gives you some ideas. :slight_smile:

You could probably also try hooking on to this WP function and add your own validation… https://developer.wordpress.org/reference/functions/is_email/

Ok great, that helped thanks. I used the used the below:

    function update_post_vars_for_registration()
    {
	$email = get_email();
	if(email_is_valid($email)){
		//continue registration
	}else{
		//stop registration
		$_POST["s2member_pro_stripe_checkout"]["email"] = '';
		
		/create error message
		GLOBAL $response_extra;
		
		$response_extra = '	
		<div id="s2member-pro-stripe-registration-form-response-section" class="s2member-pro-stripe-form-section s2member-pro-stripe-registration-form-section s2member-pro-stripe-form-response-section s2member-pro-stripe-registration-form-response-section">
			<div id="s2member-pro-stripe-registration-form-response-div" class="s2member-pro-stripe-form-div s2member-pro-stripe-registration-form-div s2member-pro-stripe-form-response-div s2member-pro-stripe-registration-form-response-div">
			<div id="s2member-pro-stripe-form-response" class="s2member-pro-stripe-form-response-error s2member-pro-stripe-registration-form-response-error">You cannot register for a large organization account with an email address in the domain you specified. You will need to use an email address with your own under your own control. Please try again with a valid email or contact us if you wish to register.</div>
			</div>
		<div style="clear:both;"></div>';
	}
    {
    add_action('init', 'update_post_vars_for_registration', 1);


    add_action('ws_plugin__s2member_pro_before_sc_stripe_form','extra_validation',10);
    function extra_validation ($vars = array()) {

	   if(isset($GLOBALS['response_extra'])) {
		echo $GLOBALS['response_extra'];
	    }
    }

thanks!

2 Likes