0

I've created a multi-part tabbed registration form that includes about 40-45 custom fields aside from user name, password and email. The goal is to create a new user registration and store the validated / sanitized contents of the field inputs into a new table in the database. This table will be used as a registry and searched by public users.

When I call wp_create_user, the only 3 allowable arguments are user name, password and email. Is there another hook I should call that will post in my other fields?

Here is my form thus far:

class qfpregister extends WP_Widget
{
  static private $login_registration_status;
  static function registration_form(){
    $username = esc_attr( $_POST['username']);
    $password = esc_attr( $_POST['password']);
    $firstname = esc_attr( $_POST['firstname']);
    $middlename = esc_attr( $_POST['middlename']);
    $lastname = esc_attr( $_POST['lastname']);
    $companyname = esc_attr($_POST['companyname']);
    $dateofbirth = esc_attr($_POST['dateofbirth']);
    $ssn = esc_attr($_POST['ssn']);
    $workaddress1 = esc_attr($_POST['workaddress1']);
    $workaddress2 = esc_attr($_POST['workaddress2']);
    $workcity = esc_attr($_POST['workcity']);
    $workstate = esc_attr($_POST['workstate']);
    $workzipcode = esc_attr($_POST['workzipcode']);
    $homeaddress1 = esc_attr($_POST['homeaddress1']);
    $homeaddress2 = esc_attr($_POST['homeaddress2']);
    $homecity = esc_attr($_POST['homecity']);
    $homestate = esc_attr($_POST['homestate']);
    $homezipcode = esc_attr($_POST['homezipcode']);
    $phone = esc_attr($_POST['phone']);
    $fax = esc_attr($_POST['fax']);
    $email = esc_attr($_POST['email']);
    $website = esc_attr($_POST['website']);
    $biography = esc_attr($_POST['biography']);
    $photofilename = esc_attr($_POST['photofilename']);
    $billingsameashome = esc_attr($_POST['billingsameashome']);
    $billingsameaswork = esc_attr($_POST['billingsameaswork']);
    $chfcearneddate = esc_attr($_POST['chfcearneddate']);
    $chfccert = esc_attr($_POST['chfccert']);
    $pfsearneddate = esc_attr($_POST['pfsearneddate']);
    $pfscert = esc_attr($_POST['pfscert']);
    $msfsearneddate = esc_attr($_POST['msfsearneddate']);
    $msfscert = esc_attr($_POST['msfscert']);
    $msearneddate = esc_attr($_POST['msearneddate']);
    $mscert = esc_attr($_POST['mscert']);
    $qfpearneddate = esc_attr($_POST['qfpearneddate']);
    $qfpcert = esc_attr($_POST['qfpcert']);
    $othercreds = esc_attr($_POST['othercreds']);
    $regtype = esc_attr($_POST['regtype']);
    $ccnumber = esc_attr($_POST['ccnumber']);
    $ccexpmonth = esc_attr($_POST['ccexpmonth']);
    $ccexpyear = esc_attr($_POST['ccexpyear']);
    $cvvnumber = esc_attr($_POST['cvvnumber']);
    /*
{
    $html =
    '<div>';
        $html .= '<!-- Nav Tabs -->';
        $html .= '<ul class="nav nav-tabs" role="tablist">';
            $html .= '<li role="presentation" class="active"><a href="#contactinfo" aria-controls="contactinfo" role="tab"
             data-toggle="tab">Contact Info</a></li>';
            $html .= '<li role="presentation"><a href="#designations" aria-controls="designations" role="tab"
            data-toggle="tab">Underlying Qualifying Designations</a></li>';
            $html .= '<li role="presentation"><a href="#attestation" aria-controls="attestation" role="tab"
             data-toggle="tab">Attestation</a></li>';
        $html .= '</ul>';
    $html .= '</div>';
   $html .= '<div class="tab-content">';
   $html .=  '<div role="tabpanel" class="tab-pane active container-fluid" id="contactinfo">';
        $html .= '<form action = "' . $_SERVER['REQUEST_URI'] . '" method = "post" enctype="multipart/form-data">';
            $html .= '<div class = "row">';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for = "username">Username <strong>*</strong></label>';
                    $html .= '<input type = "text" name = "username" value = "username">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for = "firstname">First Name <strong>*</strong></label>';
                    $html .= '<input type = "text" name = "firstname" value = "firstname">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for = "middlename">Middle Name </label>';
                    $html .= '<input type = "text" name = "middlename" value = "middlename">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for = "lastname">Last Name <strong>*</strong></label>';
                    $html .= '<input type="text" name="lastname" value = "lastname">';
                $html .= '</div>';
            $html .= '</div>';
            $html .= '<div class="row">';
                $html = '<div class="col-md-3">';
                    $html .= '<label for = "passowrd">Password <strong>*</strong></label>';
                    $html .= '<input type = "password" name = "password" value = "password">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for = "companyname">Company Name</label>';
                    $html .= '<input type="text" name="companyname" value = "companyname">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="dateofbirth">Date of Birth <strong>*</strong></label>';
                    $html .= '<input type="date" name="dateofbirth" value = "dateofbirth">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="ssn">Social Security Number <strong>*</strong></label>';
                    $html .= '<input pattern="{d3}-{d2}-{d4}" name="ssn" value = "ssn">';
                $html .= '</div>';
            $html .= '</div>';
            $html .= '<div class="row">';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for = "phone">Phone Number <strong>*</strong></label>';
                    $html .= '<input type="text" name="phone" value = "phone">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for = "fax">Fax</label>';
                    $html .= '<input type="text" name = "fax" value = "fax">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="email">Email <strong>*</strong></label>';
                    $html .= '<input type="text" name = "email" value = "email">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="website">Website</label>';
                    $html .= '<input type="text" name="website" value="website">';
                $html .= '</div>';
            $html .= '</div>';
            $html .= '<div class="row">';
                $html .= '<div class="col-md-3">';
                    $html .= '<label><strong>Business Address</strong></label>';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label><strong>Home Address</strong></label>';
                $html .= '</div>';
            $html .= '</div>';
            $html .= '<div class="row">';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="workaddress1">Business Address 1</label>';
                    $html .= '<input type="text" name="workaddress1" value="workaddress1">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="homeaddress1">Home Address 1</label>';
                    $html .= '<input type="text" name="homeaddress1" value="homeaddress1">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="bio">Biography / Areas of Specialty</label>';
                    $html .= '<input type="text"  name="bio" >';
                $html .= '</div>';
            $html .= '</div>';
            $html .= '<div class="row">';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="workaddress2">Business Address 2</label>';
                    $html .= '<input type="text" name="workaddress2" value="workaddress2">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="homeaddress2">Home Address 2</label>';
                    $html .= '<input type="text" name="homeaddress2" value="homeaddress2">';
                $html .= '</div>';
            $html .= '</div>';
            $html .= '<div class="row">';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="workcity">City</label>';
                    $html .= '<input type="text" name="workcity" value="workcity">';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="homecity">City</label>';
                    $html .= '<input type="text" name="homecity" value="homecity">';
                $html .= '</div>';
            $html .= '</div>';
            $html .= '<div class="row">';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="workstate">State</label>';
                    $html .= '<select name="workstate" type="text">';
                        $html .= '<option value="">Select...</option>';
                        $html .= '<option value="AL">Alabama</option>';
                        $html .= '<option value="AK">Alaska</option>';
                        $html .= '<option value="AZ">Arizona</option>';
                        $html .= '<option value="AR">Arkansas</option>';
                        $html .= '<option value="CA">California</option>';
                        $html .= '<option value="CO">Colorado</option>';
                        $html .= '<option value="CT">Connecticut</option>';
                        $html .= '<option value="DC">District of Columbia</option>';
                        $html .= '<option value="DE">Delaware</option>';
                        $html .= '<option value="FL">Florida</option>';
                        $html .= '<option value="GA">Georgia</option>';
                        $html .= '<option value="HI">Hawaii</option>';
                        $html .= '<option value="ID">Idaho</option>';
                        $html .= '<option value="IL">Illinois</option>';
                        $html .= '<option value="IN">Indiana</option>';
                        $html .= '<option value="IA">Iowa</option>';
                        $html .= '<option value="KS">Kansas</option>';
                        $html .= '<option value="KY">Kentucky</option>';
                        $html .= '<option value="LA">Louisiana</option>';
                        $html .= '<option value="ME">Maine</option>';
                        $html .= '<option value="MD">Maryland</option>';
                        $html .= '<option value="MA">Massachusetts</option>';
                        $html .= '<option value="MI">Michigan</option>';
                        $html .= '<option value="MN">Minnesota</option>';
                        $html .= '<option value="MS">Mississippi</option>';
                        $html .= '<option value="MO">Missouri</option>';
                        $html .= '<option value="MT">Montana</option>';
                        $html .= '<option value="NE">Nebraska</option>';
                        $html .= '<option value="NV">Nevada</option>';
                        $html .= '<option value="NH">New Hampshire</option>';
                        $html .= '<option value="NJ">New Jersey</option>';
                        $html .= '<option value="NM">New Mexico</option>';
                        $html .= '<option value="NY">New York</option>';
                        $html .= '<option value="NC">North Carolina</option>';
                        $html .= '<option value="ND">North Dakota</option>';
                        $html .= '<option value="OH">Ohio</option>';
                        $html .= '<option value="OK">Oklahoma</option>';
                        $html .= '<option value="OR">Oregon</option>';
                        $html .= '<option value="PA">Pennsylvania</option>';
                        $html .= '<option value="RI">Rhode Island</option>';
                        $html .= '<option value="SC">South Carolina</option>';
                        $html .= '<option value="SD">South Dakota</option>';
                        $html .= '<option value="TN">Tennessee</option>';
                        $html .= '<option value="TX">Texas</option>';
                        $html .= '<option value="UT">Utah</option>';
                        $html .= '<option value="VA">Virginia</option>';
                        $html .= '<option value="VT">Vermont</option>';
                        $html .= '<option value="WA">Washington</option>';
                        $html .= '<option value="WV">West Virginia</option>';
                        $html .= '<option value="WI">Wisconsin</option>';
                        $html .= '<option value="WY">Wyoming</option>';
                    $html .= '</select>';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="homestate">State</label>';
                    $html .= '<select name="homestate" type="text">';
                    $html .= '<option value="">Select...</option>';
                    $html .= '<option value="AL">Alabama</option>';
                    $html .= '<option value="AK">Alaska</option>';
                    $html .= '<option value="AZ">Arizona</option>';
                    $html .= '<option value="AR">Arkansas</option>';
                    $html .= '<option value="CA">California</option>';
                    $html .= '<option value="CO">Colorado</option>';
                    $html .= '<option value="CT">Connecticut</option>';
                    $html .= '<option value="DC">District of Columbia</option>';
                    $html .= '<option value="DE">Delaware</option>';
                    $html .= '<option value="FL">Florida</option>';
                    $html .= '<option value="GA">Georgia</option>';
                    $html .= '<option value="HI">Hawaii</option>';
                    $html .= '<option value="ID">Idaho</option>';
                    $html .= '<option value="IL">Illinois</option>';
                    $html .= '<option value="IN">Indiana</option>';
                    $html .= '<option value="IA">Iowa</option>';
                    $html .= '<option value="KS">Kansas</option>';
                    $html .= '<option value="KY">Kentucky</option>';
                    $html .= '<option value="LA">Louisiana</option>';
                    $html .= '<option value="ME">Maine</option>';
                    $html .= '<option value="MD">Maryland</option>';
                    $html .= '<option value="MA">Massachusetts</option>';
                    $html .= '<option value="MI">Michigan</option>';
                    $html .= '<option value="MN">Minnesota</option>';
                    $html .= '<option value="MS">Mississippi</option>';
                    $html .= '<option value="MO">Missouri</option>';
                    $html .= '<option value="MT">Montana</option>';
                    $html .= '<option value="NE">Nebraska</option>';
                    $html .= '<option value="NV">Nevada</option>';
                    $html .= '<option value="NH">New Hampshire</option>';
                    $html .= '<option value="NJ">New Jersey</option>';
                    $html .= '<option value="NM">New Mexico</option>';
                    $html .= '<option value="NY">New York</option>';
                    $html .= '<option value="NC">North Carolina</option>';
                    $html .= '<option value="ND">North Dakota</option>';
                    $html .= '<option value="OH">Ohio</option>';
                    $html .= '<option value="OK">Oklahoma</option>';
                    $html .= '<option value="OR">Oregon</option>';
                    $html .= '<option value="PA">Pennsylvania</option>';
                    $html .= '<option value="RI">Rhode Island</option>';
                    $html .= '<option value="SC">South Carolina</option>';
                    $html .= '<option value="SD">South Dakota</option>';
                    $html .= '<option value="TN">Tennessee</option>';
                    $html .= '<option value="TX">Texas</option>';
                    $html .= '<option value="UT">Utah</option>';
                    $html .= '<option value="VA">Virginia</option>';
                    $html .= '<option value="VT">Vermont</option>';
                    $html .= '<option value="WA">Washington</option>';
                    $html .= '<option value="WV">West Virginia</option>';
                    $html .= '<option value="WI">Wisconsin</option>';
                    $html .= '<option value="WY">Wyoming</option>';
                    $html .= '</select>';
                $html .= '</div>';
            $html .= '</div>';
            $html .= '<div class="row">';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for "workzip">Work Zip Code</label>';
                    $html .= '<input type="text" name="workzip" value="workzip"/>';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="homezip">Home Zip Code</label>';
                    $html .= '<input type="text" name="homezip" value="homezip"/>';
                $html .= '</div>';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="billingsameashome">Billing Address Same as Home Address?</label>';
                    $html .= '<input type="checkbox" name="billingsameashome" value="billingsameashome"/><br/>';
                    $html .= '<label for="billingsameaswork">Billing Address Same as Work Address?</label>';
                    $html .= '<input type="checkbox" name="billingsameaswork" value="billingsameaswork"/><br/>';
                $html .= '</div';
                $html .= '<div class="col-md-3">';
                    $html .= '<label for="photologfilename">Photo/Logo Filename</label>';
                    $html .= '<input type="file" name="photologfilename" value="photologofilename"/>';
                    $html .= '<input type="submit" name="contactnext"/>';
                $html .= '</div>';
            $html .= '</div>'; // close tabpane

    return $html;
 }

}

What function(s) should be called to add the new user and the corresponding data as meta inputs on the user record?

  • You can store your additional data as user meta, or if you need to make db queries to insert your fields, you can add_action('user_register', 'my_insert_callback', 10, 1) . This passes the new inserted user id to the callback function – czerspalace Jul 1 '16 at 18:38
  • So, it sounds like I need a two-step process. The first is to register the user and the second is to add all the contents from the registration as additional data fields? Should the plugin have a separate step for creating the meta fields, or can all this be done when the user is created? – SidC Jul 1 '16 at 20:04
  • This can all be done at the same time. In the my_insert_callback function you would have access to the newly created user id, like my_insert_callback($user_id). In that function, you will perform your db queries (or meta inserts) – czerspalace Jul 1 '16 at 20:50
  • if you have a code example of how you call create user, that would be helpful in guiding you where to make the additional calls – czerspalace Jul 1 '16 at 20:51
  • Updated with code sample. – SidC Jul 1 '16 at 21:11
0

In the function that you're hooking into user_register, you need to create the user and save the values. First, I'd recommend using wp_insert_user() instead of wp_create_user().

You might do something like this:

$userdata = array(
    'user_email'  => $email_address,
    'user_login'  => $user_name,
    // this is automatically salted
    'user_pass'   => 'plain_text_password',
);

// this function returns the user id
$user_id = wp_insert_user( $userdata ) ;

$data = array(
    'field_key_name' => $data_one,
    'field_key_name_two' => $data_two,
    );

foreach( $data as $k => $v ) {
    update_user_meta( $user_id, $k, $v );
}

// if wp_insert_user fails, it returns an error object
if ( is_wp_error( $user_id ) ) {
    // error
} else {
    // success
}

If you are saving the data to a custom table, you would perform that update query in place of update_user_meta(), which saves your data to the wp_usermeta table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.