latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Verify terms and conditions on server-side

Home Forums Community Forum Verify terms and conditions on server-side

This topic contains 11 replies, has 3 voices. Last updated by  alancheuk 3 years, 11 months ago.

Topic Author Topic
Posted: Wednesday Dec 26th, 2012 at 5:57 pm #35524
alancheuk
Username: alancheuk

I posted on an older thread about this problem (http://www.s2member.com/forums/topic/force-terms-conditions-at-checkout/), but there has been no response. It occurred to me perhaps I was supposed to start a new thread for this, so here it is.

I added a custom field for accepting terms and conditions to pro forms as described here:

http://www.s2member.com/kb/force-terms-and-conditions-agreement/

However, I noticed that there is only javascript checking of the checkbox. I want to add server-side checking because I want to ensure that everyone who signs up for an account must have checked the box. How do I go about doing this? What hook or other mechanism should I use for verification?

Thanks!

List Of Topic Replies

Viewing 11 replies - 1 through 11 (of 11 total)
Author Replies
Author Replies
Posted: Thursday Dec 27th, 2012 at 3:30 pm #35572
Bruce
Username: Bruce
Staff Member

Hi Alan,

I see that you’re right about s2Member only checking this value through JavaScript. I’ll ask Jason about verifying through PHP.

Thanks for your patience.

Posted: Friday Dec 28th, 2012 at 1:30 pm #35646
Bruce
Username: Bruce
Staff Member

Hi Alan,

We’d recommend using the ws_plugin__s2member_during_configure_user_registration_front_side hook, found in /s2member/includes/classes/registrations.inc.php.

Something like this:

Posted: Friday Dec 28th, 2012 at 7:49 pm #35672
alancheuk
Username: alancheuk

Dear Bruce,

Thank you for the help. Unfortunately, I am not so good at this and could really use a little more guidance.

It looks like by the time that hook is triggered, the user has already been registered. Do I need to unregister the user? How do I pass an error message back out so that it shows up for the user?

Thank you!

Posted: Saturday Dec 29th, 2012 at 3:03 pm #35732
Bruce
Username: Bruce
Staff Member

Hi Alan,

This action hook comes while s2Member is still setting up variables, at line 609. s2Member begins processing the user at line 763, so you still have the opportunity to die() or exit() the script.

Posted: Sunday Dec 30th, 2012 at 5:20 am #35788
alancheuk
Username: alancheuk

The reason that I suspected that the user is already created at that point is because I already tried throwing an exit(); in the error check, but the user was still being created. I checked again a second ago to make sure.

So here is the code that I am using:

function ss_registration_validation($vars = array())
{
$fields = $vars[‘fields’];
$errors = new WP_Error();
if (empty($fields[‘agree_terms_conditions’]))
{
// Handle error reporting here.
echo “ERROR”;
exit();
}
}
add_action(‘ws_plugin__s2member_during_configure_user_registration_front_side’, ‘ss_registration_validation’);

Then I register a free account without checking the box. The “ERROR” message is output, but I can then go back and login with the new username/password I created.

So how do I stop the user from being created? And is there a way to send back a pretty error message, like the kind you get when there is no email or password entered?

Thanks!

Posted: Saturday Jan 5th, 2013 at 2:31 pm #36304
Bruce
Username: Bruce
Staff Member

Hi Alan

I’m very, very sorry about the delay

The only other way I see to accomplish this is like so:

add_action('ws_plugin__s2member_before_configure_user_registration', 'ss_registration_validation');

function ss_registration_validation($vars = array()) {
	$_p = $_POST;
	
	if(!isset($_p['ws_plugin__s2member_custom_reg_field_field_name']))
		exit('Error: you have attempted to pass an invalid configuration.');
}
Posted: Friday Jan 11th, 2013 at 7:50 am #36965
alancheuk
Username: alancheuk

Dear Bruce,

I tried it out the code you gave (with the correct custom field name) and it still doesn’t work. I get the error message, but the account is still made… Is there an earlier hook that I can use that will get hit before the user is created?

add_action('ws_plugin__s2member_before_configure_user_registration', 'ss_registration_validation');
function ss_registration_validation($vars = array()) {
	$_p = $_POST;

	if(!isset($_p['ws_plugin__s2member_custom_reg_field_agree_terms_conditions']))
		exit('Error: you have attempted to pass an invalid configuration.');
}

Thanks!
Alan

Posted: Saturday Jan 12th, 2013 at 1:15 pm #37141
Staff Member

Thanks for the heads up on this thread :-)

This is how you might handle this.
Use the login_form_register hook please, it comes VERY early on.
This hook is built into WordPress itself.

Please create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
(NOTE: these are MUST USE plugins, see: http://codex.wordpress.org/Must_Use_Plugins)
(See also: http://www.s2member.com/kb/hacking-s2member/)

Posted: Saturday Jan 12th, 2013 at 4:56 pm #37183
alancheuk
Username: alancheuk

Dear Jason,

Thank you. Unfortunately that action is too soon. I tried it. It runs the check when the registration form is loaded on /wp-login.php?action=register, and fails, preventing users from registering.

I ended up successfully using the “pre_user_login” wordpress filter instead.

Alan

Posted: Sunday Jan 13th, 2013 at 2:42 am #37210
Staff Member

Thanks for the follow-up :-)

Glad you got this working. Keep in mind that the action hook login_form_register, while it is called VERY early-on, is actually better suited to this, because it’s an action that is ONLY called during registration. The line in the hack I posted above, checks for the POST action, indicating the form is being submitted, so it will not interfere with the initial page view of your registration form. If that’s not working properly on your server, you can add one additional check, which tests to see if the $_POST array is empty or not. See below.

Posted: Monday Jan 14th, 2013 at 7:34 pm #37545
alancheuk
Username: alancheuk

Thanks Jason, it works great. I totally missed the conditional statement in your code, I just assumed the only thing that changed in the code block from Ryan’s suggestion was the hook. My mistake.

Viewing 11 replies - 1 through 11 (of 11 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.