I would like to create a multi-step registration process.
After registering the user would be redirected to the Gravity Form. They would be asked a series of questions (eg. address).
The function below can handle adding the data into the usermeta table.
<?php }
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_usermeta( $user_id, 'address', $_POST['address'] );
update_usermeta( $user_id, 'city', $_POST['city'] );
update_usermeta( $user_id, 'state', $_POST['state'] );
update_usermeta( $user_id, 'postalcode', $_POST['postalcode'] );
}
?>
My question is: How can I tie this function in with the Gravity Forms pre or post submission hook to get data from the field to the usermeta table?
I've been successful at adding new fields to the profile page which allows the user to add/edit usermeta, but I'm not wanting to rely on the profile page because I would like to make some of the fields required.
The code I used to do that is below.
<?php
add_action( 'show_user_profile', 'extra_user_profile_fields' );
add_action( 'edit_user_profile', 'extra_user_profile_fields' );
function extra_user_profile_fields( $user ) { ?>
<h3><?php _e("Extra profile information", "blank"); ?></h3>
<table class="form-table">
<tr>
<th><label for="address"><?php _e("Address"); ?></label></th>
<td>
<input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your address."); ?></span>
</td>
</tr>
<tr>
<th><label for="city"><?php _e("City"); ?></label></th>
<td>
<input type="text" name="city" id="city" value="<?php echo esc_attr( get_the_author_meta( 'city', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your city."); ?></span>
</td>
</tr>
<tr>
<th><label for="state"><?php _e("State"); ?></label></th>
<td>
<input type="text" name="state" id="state" value="<?php echo esc_attr( get_the_author_meta( 'state', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your state."); ?></span>
</td>
</tr>
<tr>
<th><label for="postalcode"><?php _e("Postal Code"); ?></label></th>
<td>
<input type="text" name="postalcode" id="postalcode" value="<?php echo esc_attr( get_the_author_meta( 'postalcode', $user->ID ) ); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your postal code."); ?></span>
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'save_extra_user_profile_fields' );
add_action( 'edit_user_profile_update', 'save_extra_user_profile_fields' );
function save_extra_user_profile_fields( $user_id ) {
if ( !current_user_can( 'edit_user', $user_id ) ) { return false; }
update_usermeta( $user_id, 'address', $_POST['address'] );
update_usermeta( $user_id, 'city', $_POST['city'] );
update_usermeta( $user_id, 'state', $_POST['state'] );
update_usermeta( $user_id, 'postalcode', $_POST['postalcode'] );
}
?>
Thank you