Page 1 of 1

Custom registration field help

PostPosted: March 25th, 2011, 1:48 pm
by kiawah1
In the custom registration field area, I am trying to add a drop down so when they register they will see the current S1 and S2 User names in the drop down. These are for referral fee purposes but I cannot figure out how to have the system pull the user names. Can anyone tell me the best way to do this? Thanks!

Re: Custom registration field help

PostPosted: March 25th, 2011, 8:01 pm
by Cristián Lávaque
I'm sorry, it probably is very obvious but I'm not understanding the question well. What are the S1 and S2 usernames?

Re: Custom registration field help

PostPosted: March 26th, 2011, 5:14 pm
by Jason Caldwell
Custom Registration Fields ( a developer how-to )

How to set option values dynamically,
and how to set a default selected option value too.


Create this directory and file:
/wp-content/mu-plugins/s2-hacks.php
Code: Select all
<?php
/*
Setting options dynamically for Custom Registration Fields.
*/
add_action ("ws_plugin__s2member_before_custom_field_gen", "my_dynamic_field_options");
function my_dynamic_field_options ($vars = array ())
    {
        $_field = &$vars["__refs"]["_field"]; /* By "reference". */
        /* See: http://www.php.net/manual/en/language.references.spot.php. */
        /**/
        if ($_field["id"] === "country_code")
            {
                $_field["options"] = "US|United States|default" . "\n";
                $_field["options"] .= "CA|Canada" . "\n";
                $_field["options"] .= "VI|Virgin Islands (U.S.)";
            }
    }
/*
Setting a default value for Custom Registration Fields.
*/
add_action ("ws_plugin__s2member_before_custom_field_gen", "my_dynamic_field_values");
function my_dynamic_field_values ($vars = array ())
    {
        $references = &$vars["__refs"]; /* Array of variable "references". */
        $_field = &$vars["__refs"]["_field"]; /* By "reference". */
        /* See: http://www.php.net/manual/en/language.references.spot.php. */
        /**/
        if ($_field["id"] === "country_code")
            {
                if (empty ($references["_submission"]) && empty ($references["_value"]))
                    /* If a form was not just submitted. And, there is no default value. */
                    
                    $references
["_value"] = "CA"; /* Set the default value. */
            }
    }
?>

Video
I'm also attaching a video tutorial on this topic,
where I explain how this code works in great detail.

MP4 Video file: http://www.s2member.com/wp-content/uplo ... ically.mp4

Re: Custom registration field help

PostPosted: March 30th, 2011, 7:44 am
by kiawah1
Thank you for the tutorial. This should be a big help.

Re: Custom registration field help

PostPosted: October 26th, 2011, 11:59 am
by nemoprincess
Hi Jason, I have the same need, to add automatically some values of a select for my custom registration field. I have tried your code, but I get a blank page when I try to go to mywebsite/wp-admin
I' m using the latest versions of both Wordpress and the pro versione of S2Member.
Could you help me please? Thanks a lot

Re: Custom registration field help

PostPosted: October 26th, 2011, 12:27 pm
by Jason Caldwell
Thanks for the follow-up.
nemoprincess wrote:Hi Jason, I have the same need, to add automatically some values of a select for my custom registration field. I have tried your code, but I get a blank page when I try to go to mywebsite/wp-admin
I' m using the latest versions of both Wordpress and the pro versione of S2Member.
Could you help me please? Thanks a lot
It sounds like you *might* have leading or trailing white-space characters in your hacks file. This may have happened when you copied from the forum. I'm attaching a zip file with the proper syntax. Please let us know if you continue to have trouble in this regard.

Re: Custom registration field help

PostPosted: October 26th, 2011, 12:36 pm
by nemoprincess
Ops...sorry, you' re right, Thanks