Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to put a value from the registration form into a function


  • peterverkooijen
    Participant

    @peterverkooijen

    I want to consistently run function xprofile_sync_wp_profile() during registration.

    As it is the function takes fullname data from the database when the user is logged in, so it can not be run during registration.

    For a plugin that does what I need I’d have to take the fullname name value straight from the registration form, so I would have to change this line in the xprofile_sync_wp_profile() function:

    $fullname = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $bp->loggedin_user->id );

    What should I put after = to get the fullname value from the form?

    I’ve studied the bp-xprofile-signup.php file, but in the code the fullname value is part of an array (?) identified by field_id, which I know is ‘1’ for fullname, but there I get lost, way too complicated php stuff for me. Something like this?!:

    $fields = BP_XProfile_Field::get_signup_fields();

    if ( $fields ) {
    foreach ( $fields as $field ) {

    $value = $_POST['field_' . $field->id];

    $field->id = '1';

    $fullname = $value;

    Please help if anyone can. If I can figure this out, I can probably solve several other problems I have been boring you with for the last few months.

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

  • peterverkooijen
    Participant

    @peterverkooijen

    Anyone?

    Where exactly and when do you want your code to run?


    peterverkooijen
    Participant

    @peterverkooijen

    Thanks for responding DJPaul!

    I guess the hook would be this:

    user_register

    Runs when a user’s profile is first created. Action function argument: user ID.

    Or maybe this?

    register_post

    Runs before a new user registration request is processed.

    I have a wish list of things I need to do with input from the registration form:

    1. synchronize fullname with wp_usermeta firstname + last name

    2. autogenerate username/blogurl from fullname

    3. add new user to the ListMessenger mailing list

    They all require taking input from the registration form, processing the input and then storing the results in specific database tables. I’m trying to puzzle together one or more plugins to do that.


    peterverkooijen
    Participant

    @peterverkooijen

    Where exactly and when do you want your code to run?

    Shorter version: In a plugin hooked to user_register or register_post – not sure which one.

    Does anyone know how to intercept input from the registration form to “do stuff” with it?


    peterverkooijen
    Participant

    @peterverkooijen

    The phplist-dual-registration plugin also takes input from registration. It has this function:

    function subscribe($input_data) {
    if (!wpphplist_check_curl()) {
    echo 'CURL library not detected on system. Need to compile php with cURL in order to use this plug-in';
    return(0);
    }
    // $post_data = array();
    foreach ($input_data as $varname => $varvalue) {
    $post_data[$varname] = $varvalue;
    }
    // Ensure email is provided
    $email = $post_data[$this->email_id];
    // $tmp = $_POST['lid'];
    // if ($tmp != '') {$lid = $tmp; } //user may override default list ID
    if ($email == '') {
    echo('You must supply an email address');
    return(0);
    }
    // 3) Login to phplist as admin and save cookie using CURLOPT_COOKIEFILE
    // NOTE: Must log in as admin in order to bypass email confirmation
    $url = $this->domain . "admin/";
    $ch=curl_init();
    if (curl_errno($ch)) {
    print '<h3 style="color:red">Init Error: ' . curl_error($ch) .' Errno: '. curl_errno($ch) . "</h3>";
    return(0);
    }

    $post_data='action=subscribe&group_ids[]='.$this->lid.'&email_address='.$this->email_id.'&firstname='.$this->name_id;

    Is the $post_data line what I need? Something like this?:

    function subscribe($input_data) {

    // $post_data = array();
    foreach ($input_data as $varname => $varvalue) {
    $post_data[$varname] = $varvalue;
    }

    $email = $post_data[$this->email_id];
    $name = $post_data[$this->name_id];
    }

    And then I could use $email and $name in my function to “do stuff” with?

    Or can I use $post_data[$this->email_id] etc. directly? Is that the simple answer to my original question?

    Why is the $post_data commented out?! Don’t I need it?

    Do I need other pieces to make it work? For which fields would this work; only those from wp_users or xprofile as well? What about custom fields, including the real name/first name/last name mess?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to put a value from the registration form into a function’ is closed to new replies.
Skip to toolbar