I am trying to use GFAPI::submit_form() to add entries to an assessment form (ID=2) with the following code within functions.php.
This code should fire when a user registers with the website via another user registration form (ID = 1) that has a User Registration Feed set up to create a user.
The code hooks into ‘gform_user_registered’ the Gravity Forms action to trigger an event once a user has been registered through the User Registration Add-on.
add_action( ‘gform_user_registered’, ‘gmpcc_register_update_user_profile’, 10, 4 );
function gmpcc_register_update_user_profile ($user_id, $feed, $entry, $user_pass) {
// Get values from the user registration form (ID = 1) with field IDs
$firstname = rgar( $entry, ‘2.3’ ); // First name
$lastname = rgar( $entry, ‘2.6’ ); // Last name
$email = rgar( $entry, ‘3’ ); // Email
$telephone = rgar( $entry, ‘36’ ); // Telephone
$jobtitle = rgar( $entry, ‘31’ ); // Job title
$organisation = rgar( $entry, ‘30’ ); // Organisation
$locality = rgar( $entry, ‘48’ ); // Locality
$locations_to_work = rgar( $entry, ‘50’ ); // Locations to work
$health_care_professional = rgar( $entry, ‘37’ ); // Health Care Professional
// Update user profile with custom fields
update_user_meta($user_id, ‘gmpcc_user_first_name’, $firstname);
update_user_meta($user_id, ‘gmpcc_user_last_name’, $lastname);
update_user_meta($user_id, ‘gmpcc_user_email’, $email);
update_user_meta($user_id, ‘gmpcc_user_telephone’, $telephone);
update_user_meta($user_id, ‘gmpcc_user_jobtitle’, $jobtitle);
update_user_meta($user_id, ‘gmpcc_user_organisation’, $organisation);
update_user_meta($user_id, ‘gmpcc_user_locality’, $locality);
update_user_meta($user_id, ‘gmpcc_user_locations_want_to_work’, $locations_to_work);
update_user_meta($user_id, ‘gmpcc_user_health_care_professional’, $health_care_professional);
// Add entry to assessment form (ID=2)
$input_values[‘input_1’] = $firstname; // Text field
$input_values[‘input_2’] = $lastname; // Text field
$input_values[‘input_4’] = $email; // Text field
$input_values[‘input_96’] = $telephone; // Text field
$input_values[‘input_18’] = $jobtitle; // Text field
$input_values[‘input_95’] = $organisation; // Text field
$input_values[‘input_145’] = $locality; // Select field
$input_values[‘input_168’] = $locations_to_work; // Multi-select field
$input_values[‘input_6’] = $health_care_professional; // Radio buttons field
$result = GFAPI::submit_form( 2, $input_values );
}
An entry is created in the user registration form (ID = 1) .
A user account is created.
Custom fields are added to user profile.
No entry is created in the assessment form (ID=2).
Please could you help me to troubleshoot how to get GFAPI::submit_form() to add entries.
–
Many thanks
Rowan