User Registration

Knowledge BaseExtend Formidable FormsAdd Ons → User Registration

Use a Formidable form to allow users to register and edit their profile from the front-end of your site. This add-on allows you to easily reference user meta and auto-populate forms with a logged-in user's information.

Download and install

  1. This add-on requires Formidable Forms Pro. If you haven't already done so, install and activate Formidable Forms Pro.
  2. Download the latest version of the Registration plugin.
  3. In your WordPress admin, go to 'Plugins' → 'Add New' and click the 'Upload Plugin' button at the top of the page.
  4. Upload the zip file you just downloaded in step one. Once the plugin is installed, click 'Activate Plugin' or go to the 'Plugins' page, find 'Formidable Registration' and click 'Activate'.
  5. In your WordPress admin, go to 'Formidable' → 'Plugin Licenses' and add your license key.

Beta downloads

Registration form

  1. Create a new form. Add any fields that you would like users to complete when registering for your site. Your registration form may be as simple as an email field or it may include fields for the first name, last name, avatar, password, and any additional user meta that you would like.
  2. Click on 'Settings' → 'Form Actions' → 'Register User'.
    Registration Button
  3. Connect fields from your form with the registration options. The only required option for user registration is the User Email setting.
    Registration Page
    Note: If your users are logged-in when they submit your registration form, it will edit their existing profile. It will not create a new user.
  4. Check 'Automatically log in users who submit this form' if you want users to be logged-in automatically after they submit the registration form.
  5. Add User Meta for additional information that you would like to add to the user's profile. Jump to User meta for more information.
    Register User Meta
  6. Check the Email Confirmation option if you want to verify the user's email address before they are fully registered. Jump to User moderation for more information.
    Register User Moderation
  7. Configure the Email Notification that will send when the user's registration is complete.
    Register Email Notification
  8. Publish the registration form on a page.

Allow users to edit profile

If you would like users to be able to edit their information submitted in the registration form, follow the steps below.

  1. Go into your registration form's Settings. Select 'Allow front-end editing of entries' and 'Limit number of form entries to one per (logged-in user)'.
  2. If you would like to prevent users from editing all the fields in your registration form, set the Visibility to Logged-out Users (in the field options) for each field that you do NOT want edited.
    Registration Visibility Edit
  3. Publish the registration form on a page. Most likely this will be a User Profile or Account page.

When a logged-in user goes to this page, they will be presented with the registration form already filled out with their information (excluding their password), which they can edit.

Login form

Add a login form to a widget or any page on your site.

In a widget

The easiest way to add a login form is to use the 'Login Form' widget.

    1. In your WordPress Admin, go to 'Appearance' → 'Widgets'.
    2. Drag the 'Login Form' widget into the sidebar.
    3. Open this widget and set the title, labels, styling, and other settings.

Register Widget

If you don't want this login widget to display on all pages, install the Display Widgets plugin for additional widget settings.

On a page

If you would like to add a simple login form to a page, add the following shortcode to your page.

[frm-login]
Parameters
  • label_username: Change the label of the username box. Usage: label_username="Username"
  • label_password: Change the label of the password field. Usage: label_password="Password"
  • label_remember: Change the label on the remember me checkbox. Usage: label_remember="Remember Me"
  • label_log_in: Change the label of the login button. Usage: label_log_in="Login"
  • label_logout: Change the label of the logout link. Usage: label_logout="Logout"
  • layout: Show the fields either horizontally or vertically. Usage: layout=h or layout=v
  • redirect: Redirect users after logging in. Usage: redirect="www.example.com"
  • remember: Show the checkbox to remember your users. Defaults to show it. Hide with remember=0.
  • slide: Set your form to be hidden and require a click to show it. Usage: slide=1
  • style: Use Formidable styling on your form. This is on by default. Disable Formidable styling with style=0.
  • value_username: Insert a default value into the username field. Usage: value_username="Username"
  • value_remember: Check the remember me checkbox be default. Usage: value_remember=1
  • username_placeholder: Set placeholder text in the Username field. Usage: username_placeholder="Username"
  • password_placeholder: Set placeholder text in the Password field. Usage: password_placeholder="Password"
  • show_labels: Hide the Username and Password field labels. Usage: show_labels="0"

For further customization of your login form, you may modify the following HTML ids:

  • form_id: By default, this is set to 'loginform'.
  • id_username: By default, this is set to 'user_login'.
  • id_password: By default, this is set to 'user_pass'.
  • id_remember: By default, this is set to 'rememberme'.
  • id_submit: By default, this is set to 'wp-submit'.

See the login form codex for more information on modifying the HTML ids.

Edit profile form

Create a form for users to add to or edit their profile on your site.

  1. Create a new form (make sure the registration add-on is active).
  2. Add any fields you would like. Save your form.
  3. On the form's 'Settings' page, select 'Allow front-end editing of entries', 'Limit number of form entries to one per (logged-in user)', and 'Limit form visibility and submission to (logged-in users)'.
    Register Permissions
  4. Go to 'Settings' → 'Form Actions' and add click the 'Register User' icon. Leave the registration settings as they are by default, except the items that you want to update in the user's profile. The settings below will update the user's first name, last name, and 'state' user meta when the form is submitted.
    Register User Email
    Note: When setting up a form to edit profiles, the User Email option is not required.
  5. Publish your 'Edit Profile' form on a page. When a logged-in user fills out this form, it will simply update their profile.

Change password form

If you would like to allow logged-in users to change their password from the front-end of your site, follow the instructions below.

  1. Create a new form (make sure the registration add-on is active).
  2. Add a Password field to this form.
  3. Save your form. On the form 'Settings' page, scroll down to 'Permissions' and check these boxes: 'Allow front-end editing of entries', 'Limit number of form entries to one per (logged-in user)', and 'Limit form visibility and submission to (logged-in users)'.
    Register Permissions
  4. Go to 'Settings' → 'Form Actions' and add click the 'Register User' icon. Leave all the registration settings as they are by default, except set the 'Password' option to the password field. This will not actually re-register logged-in users, it will simply update their profile.
  5. Publish your 'Change Password' form on a page.

Global settings

Choose the page where you would like logged-out users to be directed when they try to log in via wp-admin, or when they logout. The purpose of this option is to prevent logged-out users from seeing the wp-admin or wp-login.php page. Instead, you choose which page they will use to log in. Please note that this setting is optional.

  1. Go to 'Formidable' → 'Global Settings' → 'Registration'.
  2. Set the Login/Logout URL.
    Register Global Page
  3. Insert a login form on the selected page if you haven't already. If you do not insert a login form on the selected page, you will get locked out of your site.

User meta

Use the Registration add-on to easily autopopulate forms with any information your users provide in the registration form.

    1. First, go into your registration form. Click on 'Settings' → 'Form Actions' and open your registration action.
    2. In the 'User Meta' section, add a line for each field you would like to use to autopopulate other forms.
      Register User Meta
    3. Go into a form that you would like to autopopulate with user information. Add [user_meta key=address] to the field (if it is a text field) or in the field options in the Dynamic Default Value box (if it is not a text field). Replace 'address' with the meta name that you gave this item in step 2.
      Register Dynamic

Note: When you add new user meta in your registration action, it will not update existing profiles automatically.

User moderation

The Email Confirmation option under User Moderation will send an email with an activation link to your users when they register. This confirmation email will verify that the user has entered a valid email address. The user must click the activation link in the email to complete their registration. The user will not be able to log in until they have confirmed their email address.

  1. If you would like the user to confirm their email address before they can log in for the first time, tick the Email confirmation checkbox.
    Register User Moderation
  2. Select the Redirect to page where the user will be redirected when they click the activation link in their email.
  3. Select the User Role you would like them to have after verifying their email address. Users will be automatically created with a pending role, and the role will be changed after verification.

Most of the time, it's nice to present a 'Login' and 'Register' link to your logged-out users. There are many ways to do this, but here is one approach:

  1. Create a new page. Title it 'Register' and publish your registration form on the page.
  2. Create another new page. Title it 'Login' and publish a login form on the page, like this:
    [frm-login]
  3. Go onto your home page or create a new page. Insert a link to your 'Register' and 'Login' page, like this:
    <a href="url-of-register-page">Register</a> | <a href="url-of-login-page">Login</a>
  4. Now, if you want to show different content on your home page depending on whether or not your users are logged-in, you can install the Hide This plugin and put something like this on your page:
    [hide for="logged"]<a href="url-of-register-page">Register</a> | <a href="url-of-login-page">Login</a>[/hide]
    [hide for="!logged"]Content for logged-in users goes here[/hide]
    

Autopopulate forms

When using the registration add-on, it's easier than ever to autopopulate forms for your users. You can take advantage of User Meta to add extra information to a user's profile, and then autopopulate forms with that data using this shortcode:

[user_meta key="my_user_meta"]

Replace 'my_user_meta' with the key for your user meta. Also, you can use Formidable's Default Values to get basic information from a user's profile and autopopulate forms with that information. The following shortcodes fetch data from the logged-in user's profile:

  • [email] - The email address from the profile of a logged-in user
  • [login] - The login/username of a logged-in user
  • [display_name] - The display name from the profile of a logged-in user
  • [first_name] - The first name from the profile of a logged-in user
  • [last_name] - The last name from the profile of a logged-in user
  • [user_id] - The user ID (number) of a logged-in user

Just insert any of these shortcodes directly into text fields on the form builder page or in the field's Dynamic Default Value box if it is not a text field.

Additional Customizations

These code examples can be added to your theme functions.php file or a new plugin. If you want to insert code into your theme functions.php, add it at the very end of the file, before the last ?> if there is one. If you plan to update your theme, be sure to put it in a new plugin so the code won’t be lost on update.

Stop the registration email

add_filter('frm_send_new_user_notification', 'frm_stop_user_notification', 10, 4);
function frm_stop_user_notification($send, $form, $entry_id, $entry){
  return false;
}

Set the user role

Sometimes the user role may be different for different options chosen in your form. Here's an example of setting the role depending on what role is chosen in the form.

add_filter('frmreg_new_role', 'frmreg_new_role', 10, 2);
function frmreg_new_role($role, $atts){
  extract($atts);
  if($form->id == 5){
    if($_POST['item_meta'][125] == 'Author') //change 125 to the ID of your field and 'Author' to the value of your radio button
      $role = 'author';
  }
  return $role;
}

If you're using the "Email Confirmation" option in your Register action, use the code below instead:

add_filter('frmreg_new_role', 'frmreg_new_role', 10, 2);
function frmreg_new_role($role, $atts){
	if ( $atts['form']->id == 842 && isset( $atts['entry'] ) ) {
		$field_val = FrmProEntriesController::get_field_value_shortcode( array( 'field_id' => 18171, 'entry_id' => $atts['entry']->id, 'show' => 'value' ) );
		if ( $field_val == 'Option 2' ) {
			$role = 'subscriber';
		}
	}
	return $role;
}

Replace 842 with the ID of your form. Replace 18171 with the ID of the field which should determine the user's role. Replace 'Option 2' with an actual option from your field and replace 'subscriber' with any user role.

Allow front-end user creation

Use this code to allow administrators to create new users on the front-end. You may change administrator to any user role.

// Allow administrators to create new users through a Formidable form
add_filter('frmreg_required_role', 'frm_allow_front_end_user_creation');
function frm_allow_front_end_user_creation(){
  return 'administrator'; // change this to any user role
}

// Reset the default user ID in the user ID field
add_filter('frm_get_default_value', 'reset_user_id', 10, 2);
function reset_user_id($new_value, $field){
  if ( in_array( $field->id, array( 25 ) ) && current_user_can('administrator') ) { //change 25 to the ID of the userID field
    $new_value = '0';
  }
  return $new_value;
}

Change default WP sender

Use the code below to customize the default WordPress From name and email. The default WordPress name and email will be used to send an email to a new user.

add_filter('wp_mail_from', 'set_default_from_email');
function set_default_from_email($email){
 if($email == 'wordpress@yourdomain.com')
 $email = 'youraddress@yourdomain.com';
 return $email;
}
add_filter('wp_mail_from_name', 'set_default_name');
function set_default_name($name){
 if($name == 'WordPress'){
 $name = 'Your Name';
 }
 return $name;
}

Customize confirmation email

Use this code to customize the confirmation email subject and message.

// Customize activation email
add_filter( 'user_activation_notification_message', 'customize_activation_email', 20, 3 );
function customize_activation_email( $message, $activation_url, $user_id ) {
    $message = 'Thank you for registering with us! To complete your activation, please click the link below.';
    $message .= "\r\n\r\n";
    $message .= $activation_url;
    return $message;
}

// Customize activation email subject
add_filter( 'user_activation_notification_title', 'customize_activation_title', 20, 2 );
function customize_activation_title( $title, $user_id ) {
    $title = 'Activate your account';
    return $title;
}

Use HTML in Registration Email

If you are including HTML in the email content in the registrations settings, use this code to set the email type to HTML.

add_filter('frmreg_email_content_type', 'change_frmreg_email');
function change_frmreg_email(){
    return 'html';
}

Don't require a unique email

This can be used alongside a plugin that allows multiple user accounts to be registered to the same email address. This will remove the error added to the email field for a non-unique email address.

add_filter( 'frm_validate_field_entry', 'check_email_error', 25, 3 );
function check_email_error( $errors, $field, $value ) {
  if ( $field->id == 25 ) { //change 25 to the ID of your email field
    if ( isset( $errors[ 'field'. $field->id ] ) && $errors['field'. $field->id] == 'This email address is already registered.' ) {
      unset( $errors['field'. $field->id] );
    }
  }
  return $errors;
}

Change the used email message

By default, when a user tries to register an email address that is already registered, they will see the message "This email address is already registered". This message can be translated in a PO file, but if you'd like to change the message without a PO file, you can use this function.

add_filter( 'frm_validate_field_entry', 'replace_email_error', 25, 3 );
function replace_email_error( $errors, $field, $value ) {
  if ( $field->id == 25 ) { //change 25 to the ID of your email field
    if ( isset( $errors[ 'field'. $field->id ] ) && $errors['field'. $field->id] == 'This email address is already registered.' ) {
      $errors['field'. $field->id] = 'You have already registered.'; // change your message here
    }
  }
  return $errors;
}

Prevent S2Member redirect

When a form is set to automatically log a user in, S2Member redirects before all the form actions can be completed. Prevent this redirect, and use the form settings instead.

add_action( 'frm_trigger_register_create_action', 'stop_s2m_redirect', 1 );
add_action('frm_trigger_register_update_action', 'stop_s2m_redirect', 1 );
function stop_s2m_redirect(){
  remove_action( 'wp_login', 'c_ws_plugin__s2member_login_redirects::login_redirect', 10, 2 );
}

Delete a user

When a registration form is submitted, an entry is created, as well as a user. When that entry is deleted, the user remains. This code will automatically delete the user if the entry that created them is deleted. Replace 27 with your form ID, 77 with the ID of your user ID field, and 7 with the ID of the user who posts/pages should be assigned to.

add_action('frm_before_destroy_entry', 'delete_user_with_entry');
function delete_user_with_entry( $entry_id ) {
	$entry = FrmEntry::getOne( $entry_id );

	if ( $entry->form_id == 27 ) {// change 27 to your form id
		$field_id = 77;//change 77 to the field id of your user ID field
		$user_id = FrmProEntriesController::get_field_value_shortcode( array( 'field_id' => $field_id, 'entry' => $entry_id, 'show' => 'ID' ));
		if ( $user_id ) {
			wp_delete_user( $user_id, 7 );//change 7 to the user ID to whom the deleted user's post/pages will be assigned (this can be found in your wp_users table)
		}
	}
}

If you would like to remove the user and their posts/pages, then use this line instead:

wp_delete_user( $user_id );

Modify user data before saving

You may use the frmreg_user_data hook to modify a user's meta before they are created or updated.

add_filter( 'frmreg_user_data', 'customize_my_user_data_before_save', 10, 2 );
function customize_my_user_data_before_save( $user_data, $args ) {
    if ( $args['form']->id == 25 && $args['action'] == 'update' ) {
        $user_data['display_name'] = 'my new display name';
    }
    return $user_data;
}

Hide user meta in profile

When you go to edit a user from the WordPress Users page, you will see user meta listed at the bottom of the page. Any user meta you set in your registration settings in any form will be shown here. If you'd like to prevent this from appearing, you can use this example.

remove_action( 'show_user_profile', 'FrmRegUserController::show_user_meta', 200 );
remove_action( 'edit_user_profile', 'FrmRegUserController::show_user_meta', 200 );