Create GravityForms entry from custom form [resolved]

I’m building a custom form and I need on submit to create an entry in gravityforms. Is this possible? On the submit button I’m using jQuery serializeArray() method to get all fields and their values. My problem is that I’m not sure how to map the fields to the existing fields in gravityforms. My GF fields are all with ID and using Postman, I can see that it returns value based on that ID, so I guess I should build the API request the same way… serializeArray() returns the form data in array containing name and value of the field… How should I map the fields with jQuery and send the entry to gravityforms?

Check out one of the following articles depending on which specific API you may need to implement. They give a good overview of how your data will need structured for the requests.

Submitting Forms with REST API v2
Submitting Forms with the GFAPI

Thanks, I checked those links. Using axios I have made a POST request and I’m able to create the entry… As of now I’m using hardcoded data, since the names of my fields are different from the IDs that GF requires I can’t think of other way, than to hardcode each ID. I’m unsure how to handle the checkbox groups. In my custom HTML form they use the same name, but if I try to pass a list of each value it gets skipped in the entry… Same for radio buttons… My axios post request uses this example data:

data: {
				form_id: '4',
				date_created: '2023-08-07 12:43:23',
				is_starred: '0',
				is_read: '1',
				ip: '::1',
				source_url: 'http://localhost/wp.dev/?gf_page=preview&id=176',
				created_by: '1',
				user_agent: 'Client',
				status: 'active',
				70: 'United States',
				71: 'Netherlands',
				76: 'City A',
				77: 'City B',
        12: 'Internationally, Office',
			},

In this example data Field ID 12 is skipped in the entry. In GF this is a checkbox group also in my custom HTML form the checkboxes share the same name, thus making it a checkbox group, so they are returned as array… How should I pass them, so they are not skipped in the entry?

I managed to fix my issues. For anyone else wondering, the checkboxes are saved in fieldID.optionID. In my case the field id was 12, so the options were 12.1, 12.2 & etc… So you will need to pass the values in that way:

data: {
				form_id: '4',
				date_created: '2023-08-07 12:43:23',
				is_starred: '0',
				is_read: '1',
				ip: '::1',
				source_url: 'http://localhost/wp.dev/?gf_page=preview&id=176',
				created_by: '1',
				user_agent: 'Client',
				status: 'active',
				70: 'United States',
				71: 'Netherlands',
				76: 'City A',
				77: 'City B',
        12.1: 'Internationally',
        12.2: 'Office',
			},

Managed to fix all my problems a week ago, just now I remembered to update here. Not sure how to mark the topic as solved and close it…

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Nice way to handle it.

Any reply (including your own) can be marked as a solution with the checkbox at the bottom of the thread. I’ve marked your latest as the solution for it.

For future projects, or others that may be reading this after, if mapping to the hardcoded field IDs of the entry object presents challenge to you, or you don’t want to reduce how much is defined through code, the Gravity Flow Incoming Webhook extension has a Create an Entry step type. With it, you could define what field(s) have what keys, limit what fields are submitted, or hard-code values in the request which the API call to trigger it doesn’t have to provide and more. Your approach w.r.t checkboxes would remain unchanged, OR you can even chose to have each checkbox it’s own key to map the selections.

Regards,
Jamie