Create Landing Page from a template containing a Form Module via the API

Hi,

I’m having some trouble getting landing page to create with a form module inside it.

Before the Design Manager change to widgets / modules I used to pass the id of the Form using form_to_use. This doesn’t seem to work anymore.

I can still create the Form, get the Id and then create the Landing Page, but the Form is not linked to the page.

The template block for the Form used to look like this:-

{% widget_block form “module_1520509818427313”, form_follow_ups_follow_up_type=‘’, form_to_use=‘d0021d42-79bf-4e91-9d96-127ce50806fd’, gotowebinar_webinar_key=‘’, notifications_are_overridden=False, overrideable=True, per_widget_wrapper_html=‘’, response_message=‘Thanks for submitting the form.’, response_redirect_url=‘’, response_response_type=‘redirect’, sfdc_campaign=‘’, title=‘’, wrapping_html=‘<div id=“workcast-event-form”>{{ html }}</div>’, label=‘Form’ %}

{% widget_attribute “notifications_override_email_addresses” is_json=True %}[]{% end_widget_attribute %}
{% end_widget_block %}

But in the new Design Manager it look like this:-

{% module_block module “module_1549553234621780” wrapping_html=‘<div id=“workcast-event-form”>{{ html }}</div>’, per_widget_wrapper_html=‘’, overrideable=True, widget_name=‘Form’, module_id=1155238, label=‘Form’ %}
{% module_attribute “form” is_json=True %}{“response_type”:“redirect”,“message”:“Thanks for submitting the form.”}{% end_module_attribute %}
{% end_module_block %}

so a Form is now a Module rather than a Widget.

I am passing the following JSON to the https://api.hubapi.com/content/api/v2/pages endpoint:-

{
“name”: “cjs201 Registration Landing Page”,
“html_title”: “cjs201 Registration Landing Page”,
“meta_description”: “cjs201 Registration Landing Page”,
“template_path”: “generated_layouts/7354513786.html”,
“campaign_name”: “cjs201”,
“publish_date”: 1549623024353.2068,
“publish_immediately”: “true”,
“subcategory”: “landing_page”,
“is_draft”: false,
“slug”: “cjs201-registration”,
“widgets”: {
“module_144646050862912567”: {
“body”: {
“value”: “cjs201”
}
},
“module_1520940079431362”: {
“body”: {
“value”: “18 February 2019”
}
},
“module_15495568009901036”: {
“body”: {
“notifications_override_guid_buffer”: “”,
“notifications_override_email_addresses”: null,
“response_redirect_url_label”: “Contact Us”,
“form_to_use”: “2c806b14-c11f-4be8-ada8-9cc6a266c157”,
“title”: “”,
“form_to_use_label”: “I added this”,
“notifications_are_overridden”: false,
“sfdc_campaign”: “”,
“notifications_override_guid”: “”,
“response_response_type”: “redirect”,
“response_message”: “Thank you for submitting the form.”,
“form_follow_ups_workflow_id”: “”,
“form_follow_ups_follow_up_type”: “”,
“sfdc_campaign_label”: “”,
“form_follow_ups_workflow_label”: “”,
“response_redirect_url”: “http://www.bbc.co.uk”
}
}
}
}

Do I need to change any of the above JSON to get the form to attach in the new version of the module?

Thanks

Hi @chrisstout ,

Thanks for reaching out -- the CMS APIs can defintiely be tricky! I don’t know if there was a recent change to the CMS endpoints and the way that we should be passing information, but after some testing, the way you should include the form data is place a form object on the same level as the module_id and other fields inside of a form object. The form object should be nested one level deep inside of the body object. When I got a specific page by id with the form module on the page prior to selecting a specific form to use, I was returned this JSON:

{
   body:{
      module_id:1155238,
      widget_name:"Form"
   },
   child_css:{},
   css:"",
   id:1549898972814,
   label:"Form",
   module_id:1155238,
   order:1,
   smart_type:null,
   type:"module"
}

After editing the page itself to include a specific form, I was returned this JSON:

{
   body:{
      form:{
 form_id:"4f0a06d1-90f2-4f56-bdd7-1f43ab67f252",
 form_type:"HUBSPOT",
 gotowebinar_webinar_key:null,
 message:"Thanks for submitting the form.",
 response_type:"inline"
 },
 module_id:1155238,
 title:"Bailey",
 widget_name:"Form"
   },
   child_css:{},
   css:"",
   id:1549898972814,
   label:"Form",
   module_id:1155238,
   order:1,
   smart_type:null,
   type:"module"
}

I then changed the form being used on that page, then made a PUT request with this endpoint with the information returned above, and the page was successfully updated.

Thanks that seems to have fixed it.

To get it working I nested the form_id one layer further down as you suggested at it works.

For anyone else trying to get this to work I used to have for widget_block form:-

“body”: {
“notifications_override_guid_buffer”: “”,
“notifications_override_email_addresses”: null,
“response_redirect_url_label”: “Contact Us”,
“form_to_use”: “0033cf74de6a48c4ac5d805d72d69822”,
“title”: “”,
“form_to_use_label”: “Dummy UnitTest Form [6bd6532d-2a9b-49] (Leads API)”,
“notifications_are_overridden”: false,
“sfdc_campaign”: “”,
“notifications_override_guid”: “”,
“response_response_type”: “redirect”,
“response_message”: “Thank you for submitting the form.”,
“form_follow_ups_workflow_id”: “”,
“form_follow_ups_follow_up_type”: “”,
“sfdc_campaign_label”: “”,
“form_follow_ups_workflow_label”: “”,
“response_redirect_url”: “http://62515.sites.hubspot.com/about-us/contact-us”
}

Now for a module_block form I have :-

‘body’: {
form: {
‘form_id’: ‘" + “0033cf74de6a48c4ac5d805d72d69822” + @"’,
‘form_type’: ‘HUBSPOT’,
‘gotowebinar_webinar_key’: null,
‘message’: ‘Thanks for submitting the form.’,
‘response_type’: ‘inline’
},
‘title’: ‘’,
}

I did this as part of the landing page create, so no need to do the create and then do a subsequent PUT.

Many thanks for you help.