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.

Getting Form Field Values

Home Forums Community Forum Getting Form Field Values

This topic contains 9 replies, has 3 voices. Last updated by  Cristián Lávaque 4 years, 10 months ago.

Topic Author Topic
Posted: Thursday Feb 16th, 2012 at 2:11 pm #5391

I’ve added code to mu-plugins to redirect successful subscribers (thanks to information found in this forum) to a page on my site.

function dw_reg_confirm($user_id){
//This is the url of the page you want to show after registration.

$confirm_page = “http://wpsite.com/membership-application-submitted”;

wp_redirect($confirm_page);
}

add_action(‘user_register’, ‘dw_reg_confirm’);

The page that I’m redirecting to needs to know what level of member just subscribed. Is there a way to query values of the newly completed registration form after the user has been redirected to the success page? If not, how can I query registration form values from within the redirect function? (I’m thinking I could pass the values to the success page by tacking them on the back of the redirect URL).

A related question is, “is there a way to get the name of the page that the registration is coming from?”. In other words, I have created role specific membership signup pages. Each page has it’s own PayPal Pro code to drive the registration process. Once registration is complete, the user is redirected to a success page via the mu-code above. I’m wondering if, within the function, there is a way to tell what page the user registerted from. I tried looking at $_SESSION variables but to no avail. Any suggestions would be appreciated.

List Of Topic Replies

Viewing 9 replies - 1 through 9 (of 9 total)
Author Replies
Author Replies
Posted: Friday Feb 17th, 2012 at 1:39 am #5455

Hi Debbie.

Have you tried the constant S2MEMBER_CURRENT_USER_ACCESS_LEVEL? I guess it’s safe to assume that the Level he has is the one he got, right? [hilite path]WP Admin -> s2Member -> API / Scripting -> s2Member PHP/API Constants[/hilite]

I hope that helps. :)

Posted: Saturday Feb 18th, 2012 at 1:34 am #5571

The person is not logged in when they register and the registration process does not log them in so I don’t think any of the ‘CURRENT_USER’ related constants will work. I tested a registration process using the level 2 form. The value of S2MEMBER_CURRENT_USER_ACCESS_LEVEL in the dw-reg-confirm function was ‘-1’. I would have expected it to be a ‘2’ so I think my suspicion about the constants only being viable for logged in users is correct.

Another way of asking my question….. how can I programmatically access the %%xxxxxxx%% constants that are available when customizing the new user mail message and the administrative new user notifcation message. Those constants seem to reflect the values entered into the registration form which is what I’m looking for.

Thanks.

Posted: Monday Feb 20th, 2012 at 2:25 pm #5708

An update… The S2Member registration process passes $user_id to the user_register function. Within the user_register function which Ive tweaked via code in S2-Hacks.php, I’ve tried querying the database based on user_id. But the results are either empty fields or values that don’t match the final results. Here is the code within S2-hacks.php:

function dw_reg_confirm($user_id) {
    //This is the url of the page you want to show after registration.

    //Get user role based on the user ID of the person who just completed and submitted a registration form 
    $user = new WP_User($user_id)
    $role = $user->roles[0];

    //Build the confirmation page URL and add role value as passed parameter
    $confirm_page = “http://fakesite.com/membership-application-submitted?" . $role;
 
    wp_redirect($confirm_page);
}
 
add_action(‘user_register’, ‘dw_reg_confirm’);

In this case the roles[0] value returned is ‘Subscriber’ instead of the final value which should be s2member_level2. When I use the same code on a normal WP page (manually entering the user id that was just registered), I get the expected value of ‘s2member_level2’ so it appears that sometime after invoking the user_register function and passing control to the redirect URL, S2 updates the roles[0] value from ‘ Subscriber’ to the appropriate value.

So…. the question remains… Within the user_register function, armed with the user id value, is there any way to find out what level of registration profile the user just completed?

One piece of additional informaton, I’m using the PayPal Pro forms for each level but I’m not using PayPal for any of the levels (payment is solicited on the registration confirmation page). As an example, here is the code for a level 2 registration:

[s2Member-Pro-PayPal-Form register="1" level="2" ccaps="" desc="$40 for one year membership" custom="dimpled-orb.com" tp="0" tt="D" captcha="clean" /]
Posted: Monday Feb 20th, 2012 at 10:18 pm #5787
Staff Member

Please try this Hook instead. You’ll want to Hook into s2Member’s handling of this.

<?php
	add_action("ws_plugin__s2member_during_configure_user_registration", "my_function");
	function my_function($vars_from_s2member = array())
		{
			extract($vars_from_s2member);
			/* Here are a few variables now available to you here.
			$role (s2member_level1, s2member_level2, etc)
			$level = (level number of access now granted)
			$email, $login, $ip, $custom, $subscr_id, $subscr_gateway
			$fname, $lname, $name, $pass, $user_id (WP User ID), $ccaps
			$user (a WP_User_object), $user->ID (the User's ID in WordPress)
			$fields (an array of Custom Registration Fields for s2Member) */
			
			
		}
?>
Posted: Tuesday Feb 21st, 2012 at 9:28 am #5862

Thanks Jason! This looks like exactly what I’m looking for. At the risk of exposing my ignorance, how do I tie the new hook in with the redireciton hook?

Thanks again. Your help is very much appreciated.

Posted: Thursday Feb 23rd, 2012 at 3:46 am #6089
Staff Member

Thanks for the follow-up!

Sorry Debbie. That’s all I can offer for now.
Please see our policy regarding custom coding.
s2Member® » Support Policy » Fine Lines

Posted: Thursday Feb 23rd, 2012 at 7:12 pm #6219

Thanks Jason. I understand your position but I\’m getting pretty frustrated. I\’ve put in the extraction hook every which way I can think of but the variables are not available. Here is one variation of the code I put into S2-hacks.php:

ID (the User\’s ID in WordPress)
$fields (an array of Custom Registration Fields for s2Member) */
}
add_action(\’user_register\’, \’dw_reg_confirm\’);
function dw_reg_confirm($user_id){
//This is the url of the page you want to show after registration
$confirm_page = \”http://wptestsite.com/osch_test_site/membership-application-submitted?\” . $role;
wp_redirect($confirm_page);
}
?>

Among other things, I\’ve also tried invoking the ws_plugin__s2member_during_configure_user_registration function from within the user_register hook (dw_reg_confirm) by adding the following line of code:
do_action (\”ws_plugin__s2member_during_configure_user_registration\”, get_defined_vars ());
but still no variables.

I\’ve spent a few hours looking through functions in the codex documentation but I\’m not making any progress. I understand you can\’t help me code but can you give me any hints? I will figure it out eventually but I\’m hoping you can save me a bunch of time by pointing me in the right direction.

Posted: Thursday Feb 23rd, 2012 at 8:39 pm #6227

Okay, I\’ve gone a different route. I must have asked my original question poorly. Sorry about that. I\’m now using the success shortcode on the PayPal Pro form (success = \”/myurl/?role=%%role%%\”)

My question now is… \”the final url does have the role value but it also has a bunch of additional information. Here is an example of what actual url that gets used:
/myurl/?role=s2member_level2&s2p-v=1330047038-e585e2adb0cc5c932dd12a3a11f76d54

Is there a way to strip off the excess stuff? I get the extra \”&s2p-v=1330047038-e585e2adb0cc5c932dd12a3a11f76d54\” even if I hardcode the success parameter like this:
\”/myurl/?role=s2member_level2\”

Any suggestions would be appreciated.

Thanks again for your help. Sorry if I wasn\’t clear on what I was trying to in the first place.

Posted: Friday Feb 24th, 2012 at 7:02 pm #6358

Hi Debbie.

No, that var can’t be removed.
[hilite path]Dashboard -› s2Member® -› PayPal® Pro Forms -› Custom Return URLs Upon Success -> Verify The Integrity Of Replacement Codes -> Can I get rid of the s2p-v variable?[/hilite]

Can I get rid of the s2p-v variable?

No, this variable is always passed to your Custom Return URL, it’s for important verification purposes.

Viewing 9 replies - 1 through 9 (of 9 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.