How to Build an Profile Form Using Post Submissions

Overview

Would you like to use WPForms to create a form that can collect and display profile data? You may want to have a category that is strictly a section on your site to show your author profile data. Using WPForms and WordPress Custom Fields this can be easily achieved and we’ll show you how!

Setup

There are several steps for this process and we’ll go through each one.

1) Setting up the WordPress Custom Fields

Before beginning to build your form, you’ll need to figure out what custom fields you want in your WordPress posts’. To create custom fields in WordPress, please review this tutorial.

For this tutorial, we’re going to be adding a profile page that includes the name of the author, their birthday, their favorite hobby, and some other personal but fun facts about the author.

2) Building the form

Next, create your Post Submission form and add your fields to capture the information you want in your profile post.

Create your form to capture the profile fields

3) Mapping the custom fields

Once you’ve added the fields to your form, you’ll now need to map these fields. Navigate to the Settings » Post Submissions tab to map these custom fields.

Type in the custom field name you set up in Step 1 and then from the dropdown, select the form field that maps to the correct field.

Map your form fields to your custom fields for your profile form

For example, in Step 1, we created a custom field in WordPress called birthday. In our form, we added a Date form field called Birthday.

On the Settings » Post Submissions tab, in the Custom Post Meta section, we typed in birthday for the WordPress custom field name and selected the Birthday form field from the dropdown.

4) Adding the Code Snippet

Next, add the code snippet to your site.

/**
 * Add a profile form using Post Submissions
 *
 * @link https://wpforms.com/developers/how-to-build-an-profile-form-using-post-submissions/
 */

function wpf_post_submission_custom_content( $post_id, $fields, $form_data, $entry_id ) {

    // Only do this for form #1089.
    if ( absint( $form_data['id'] ) !== 1089 ) {
        return;
    }

    /*
     * Field IDs, for reference.
     * 15 - Birthday
     * 16 - "My friends would describe me as"
     * 18 - "The most influential person in my life has been..."
     * 19 - "Five things I couldn't live without"
     * 20 - Favorite Hobby
     */

    // Below we're going to create our new custom content template,
    // using the field IDs listed above 🙂
    ob_start();
    ?>
    <h2><em>Arthur Profile</em></h2>
    <h3>"Name"</h3>
    <?php echo wpautop( esc_html( $fields[2]['value'] ) ); ?>
    <h3>Birthday</h3>
    <?php echo wpautop( esc_html( $fields[15]['value'] ) ); ?>
    <h3>"My friends would describe me as"</h3>
    <?php echo wpautop( esc_html( $fields[16]['value'] ) ); ?>
    <h3>"The most influential person in my life has been..."</h3>
    <?php echo wpautop( esc_html( $fields[18]['value'] ) ); ?>
    <h3>"Five things I couldn't live without"</h3>
    <?php echo wpautop( esc_html( $fields[19]['value'] ) ); ?>
    <h3>Favorite Hobby</h3>
    <?php echo wpautop( esc_html( $fields[20]['value'] ) ); ?>
    <?php
    $content = ob_get_clean();

    remove_filter('content_save_pre', 'wp_filter_post_kses');
    remove_filter('content_filtered_save_pre', 'wp_filter_post_kses');

    $post = array(
        'ID'           => $post_id,
        'post_content' => $content,
    );
    wp_update_post( $post );

    add_filter('content_save_pre', 'wp_filter_post_kses');
    add_filter('content_filtered_save_pre', 'wp_filter_post_kses');
}
add_action( 'wpforms_post_submissions_process', 'wpf_post_submission_custom_content', 10, 4 );

Please note that you will need to change the form ID and field ID(s) to match that you have in your form. For assistance with that, please see this tutorial.

And that’s it, your profile form post is ready for your review.

Your custom fields will now show on your profile form post

Would you like to be able to exclude certain posts and pages from your post submission forms? Take a look at our article on How to Exclude Posts, Pages or Categories From Dynamic Choices.