The default login, registration and password reset forms included in WordPress (outside the website developed with it) often do not conform to the design and branding of the site.
In the past when WordPress was a blogging engine, this was fine. WordPress has since evolved into a content management system, leading to an ever increasing demand for custom login, registration and password reset forms.
In this tutorial, we’ll learn how to build a WordPress multi-step registration form using a plugin that I’ve developed called ProfilePress.
It is worth noting that we’ve previously covered how to build custom login, registration and password reset forms with ProfilePress and a tabbed login and signup widget.
Below is the design of the multi-step registration form which we will have built by the end of this tutorial.
See the Pen Multi Step Registration Form with Progress Bar using jQuery and CSS3 by Agbonghama Collins (@collizo4sky) on CodePen.
If you want to jump ahead of this tutorial, here is a live demo of the form in a WordPress powered site.
Without further ado, let’s jump straight into building the multi-step registration form.
In the demo above, the SOCIAL PROFILES section contains a Facebook, Twitter and Google field, which aren’t present in the default WordPress user profile. As a result, we need to create contact methods for the above social profile fields in order for WordPress to save the data entered into the fields against the profile of registered users.
There are a number of online tutorials that describe how to add contact information fields to a WordPress user profile, including:
These tutorials explain that if the following code is pasted into your theme’s functions.php file, it will add a Facebook, Twitter and Google field to the contact information section in a WordPress user profile.
<span>function add_contact_methods( $user_contact ){ </span> <span>/* Add user contact methods */ </span> <span>$user_contact['facebook'] = __('Facebook Username'); </span> <span>$user_contact['twitter'] = __('Twitter Username'); </span> <span>$user_contact['google'] = __('Google+ Profile'); </span> <span>return $user_contact; </span><span>} </span> <span>add_filter('user_contactmethods', 'add_contact_methods');</span>
Using the plugin, contact information fields can be added by filling a key/label form (see image below). This is located in the Contact information settings page, where key is a unique name used internally by WordPress to recognize the field and label the field description displayed to users.
For more information, take a look at Adding contact info to WordPress profile with ProfilePress plugin.
Navigate to your WordPress profile to see the Facebook, Twitter and Google field displayed.
Having added the Facebook, Twitter and Google contact info fields to your WordPress profile, you then need to build the multi-step form via the melange feature.
I’m not going to walk us through the process of how the multi-step form is built with HTML, CSS and JavaScript. Feel free to poke around the source code to learn about that. Rather, we’ll learn how to convert the form into an actual, functioning WordPress registration form.
The melange feature of the plugin is capable of converting just about any login, registration password reset and can even edit the profile form template so that a working WordPress equivalent is available (although, this is only available in the premium version of the plugin).
With the plugin installed, click the Melange menu as shown in the image below and then the Add New button to initiate the building process.
A form will be presented to you. Fill the fields as follows.
Enter a name for the form in the Name field. Let’s call it Stride Multistep Signup Form.
Copy the HTML code of the multi-step form to the Melange Design TinyMCE editor and then replace the input fields with their respective shortcode equivalents like so:
<span><form method="post" novalidate> </span> <span><div id="msform"> </span> <span><!-- progressbar --> </span> <span><ul id="progressbar"> </span> <span><li class="active">Account Setup</li> </span> <span><li>Social Profiles</li> </span> <span><li>Personal Details</li> </span> <span></ul> </span> <span><!-- fieldsets --> </span> <span><fieldset> </span> <span><h2 class="fs-title">Create your account</h2> </span> <span><h3 class="fs-subtitle">This is step 1</h3> </span> <span>[reg-username placeholder="Username"] </span> <span>[reg-email placeholder="Email"] </span> <span>[reg-password placeholder="Password"] </span> <span><input type="button" name="next" class="next action-button" value="Next"/> </span> <span></fieldset> </span> <span><fieldset> </span> <span><h2 class="fs-title">Social Profiles</h2> </span> <span><h3 class="fs-subtitle">Your presence on social networks</h3> </span> <span>[reg-cpf key="twitter" type="text" placeholder="Twitter"] </span> <span>[reg-cpf key="facebook" type="text" placeholder="Facebook"] </span> <span>[reg-cpf key="google" type="text" placeholder="Google Plus"] </span> <span><input type="button" name="previous" class="previous action-button" value="Previous"/> </span> <span><input type="button" name="next" class="next action-button" value="Next"/> </span> <span></fieldset> </span> <span><fieldset> </span> <span><h2 class="fs-title">Personal Details</h2> </span> <span><h3 class="fs-subtitle">We will never sell it</h3> </span> <span>[reg-first-name placeholder="First Name"] </span> <span>[reg-last-name placeholder="Last Name"] </span> <span>[reg-nickname placeholder="Nickname"] </span> <span>[reg-bio placeholder="Biography"] </span> <span><input type="button" name="previous" class="previous action-button" value="Previous"/> </span> <span>[reg-submit class="submit action-button" value="Submit"] </span> <span></fieldset> </span> <span></div> </span><span></form></span>
We could have left the fields in the form the way they were without replacing them with their ProfilePress shortcode equivalent. However, using the shortcodes takes care of adding the correct name attribute for the input fields.
If you can determine the name attribute for the fields (for example, for the username field, the name attribute is reg_username), you might as well do away with using their shortcodes.
Since ProfilePress doesn’t include a text area for inserting JavaScript, the JavaScript code will go into the Melange Design field immediately after the HTML code of the form.
Note: the novalidate attribute was added to the
The above is the detailed content of Building a Multi-step Registration Form for WordPress. For more information, please follow other related articles on the PHP Chinese website!