# Display form via Form Selector in custom module

**URL:** <https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576>\
**Category:** CMS Development\
**Created:** [October 15, 2018, 3:59pm UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576 "2018-10-15T15:59:24Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craig](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/craig/32/60219_2.png) [@Craig](https://community.hubspot.com/u/Craig)\
**Post date:** [October 15, 2018, 3:59pm UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/1 "2018-10-15T15:59:24Z")

</div>

Hi everyone. I have a custom module, where a form selector is given as an option based on the user selecting ‘Form’ as the content type for this column. The other options are rich text and image, and both work fine.

However, when I try to output the form, I just get the form object as a string.

`{{ column.form }}`

returns:

`{form_id=01c7695d-bla-bla, response_type=inline, message=Thanks for submitting the form., gotowebinar_webinar_key=null}`

in the template. I’ve also tried the following:

```auto
{% set formId = column.form.form_id %}
{% form "my_form" form_to_use='"' + formId + '"' %}

```

but this returns nothing at all.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [October 16, 2018, 7:11am UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/2 "2018-10-16T07:11:38Z")

</div>

Hi @Craig,

I’ve written a small module to test this out and it works if you paste the “snippet” from the form-widget into your desired html-part.

Here are some screens and the code from my module

 ![form-switcher-1.JPG](https://d2qpr2jzcazej7.cloudfront.net/original/2X/8/8322e0cc4a087e5feee8ac2145b97cb4cfb78bb0.jpeg)  
my widgets

The code:

```auto
<div class="row">
 <div class="container">
 <div class="span12">
 {% if module.selector == "text" %}
 <div class="custom-module-text-only">{{ module.text }}</div>
 	{% elif module.selctor == "image"%}
 <div class="custom-module-text-and-image text-part">
 	{{ module.text }}
 </div>
 <div class="custom-module-text-and-image image-part">
 	{{ module.image }}
 </div>
 	{% elif module.selector == "form" %}
 <div class="custom-module-form">
 {% form form_to_use="{{ module.form.form_id }}" response_response_type="{{ module.form.response_type }}" response_message="{{ module.form.message }}" response_redirect_id="{{ module.form.redirect_id }}" response_redirect_url="{{module.form.redirect_url}}" gotowebinar_webinar_key="{{ module.module.form.gotowebinar_webinar_key }}" %}
 </div>
 {% endif %}
 </div>
 </div>
</div>

```

This is how it looks after you place it into your page/template

 ![form-switcher-2.JPG](https://d2qpr2jzcazej7.cloudfront.net/original/3X/f/6/f68b58a399016eaf6ccdee306bc16b35203183ef.jpeg)

I think the most important difference/part is, that you copy the “snippet” and not the “value”(see screen below)

 ![form-switcher-3.JPG](https://d2qpr2jzcazej7.cloudfront.net/original/3X/8/3/831e1b5a85779778c4c8fb01cb540f155b5c085c.jpeg)  
copy&paste the snippet into the desired place

regards

Anton

| ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/7/1/71232bb65bd029237c40010174d30ea2bb57cbd6.png) | Did my post help answer your query? Help the Community by **marking it as a solution** |  
| — | — |

---

<div class="post-metadata">

**Author:** ![Craig](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/craig/32/60219_2.png) [@Craig](https://community.hubspot.com/u/Craig)\
**Post date:** [October 16, 2018, 10:36am UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/3 "2018-10-16T10:36:27Z")

</div>

Hi @Anton - unfortunately this still doesn’t work for me - console error as below:

`v2.js:12 Please, pass a portal id and form id to render your HubSpot form`

Have tried adding

`portal_id="###" and portalId="###"`

but get the same console error

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [October 16, 2018, 12:09pm UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/4 "2018-10-16T12:09:31Z")

</div>

Hi @Craig,

could you post the complete code snippet of your module or a link to a page where it’s used?

Thanks

regards,

Anton

---

<div class="post-metadata">

**Author:** ![Craig](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/craig/32/60219_2.png) [@Craig](https://community.hubspot.com/u/Craig)\
**Post date:** [October 16, 2018, 1:01pm UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/5 "2018-10-16T13:01:00Z")

</div>

@Anton, sure:

```auto
{% for row in module.row %}

 	<div class="row {{ row.html_class }}">

 {% for column in row.column %}

 <div class="{{ column.column_width }}">

 {% if column.content_type == 'rich_text' %}

 {{ column.rich_text_content }}

 {% elif column.content_type == 'image' %}

 <img class="img-fluid" src="{{ column.image.src }}">

 {% elif %}

 {% elif column.content_type == 'form' %}

 {% form form_to_use="{{ module.form.form_id }}" response_response_type="{{ module.form.response_type }}" response_message="{{ module.form.message }}" response_redirect_id="{{ module.form.redirect_id }}" response_redirect_url="{{module.form.redirect_url}}" %}

 {% elif column.content_type == 'cta' %}

 	{{ cta(column.cta) }} 

 {% endif %}

 </div>

 {% endfor %}

 </div>

 {% endfor %}

```

---

<div class="post-metadata">

**Author:** ![John](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/john/32/43512_2.png) [@John](https://community.hubspot.com/u/John)\
**Post date:** [October 16, 2018, 8:14pm UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/6 "2018-10-16T20:14:40Z")

</div>

Here’s my “have you checked your pockets?” reply 😉

Do the module’s form values have default values, or are they blank?

---

<div class="post-metadata">

**Author:** ![Craig](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/craig/32/60219_2.png) [@Craig](https://community.hubspot.com/u/Craig)\
**Post date:** [October 17, 2018, 8:50am UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/7 "2018-10-17T08:50:16Z")

</div>

Hi @John - I thought my pockets were empty but I just checked and found a £1 coin - so thanks for that!

You mean the actual **form**  **fields?** Ie in the form that I select, does that form contain fields with default values?

In case you missed the bit about the portal ID error - the error I get with the code is:

`v2.js:12 Please, pass a portal id and form id to render your HubSpot form`

Thanks

---

<div class="post-metadata">

**Author:** ![Anton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anton/32/103167_2.png) [@Anton](https://community.hubspot.com/u/Anton)\
**Post date:** [October 17, 2018, 9:26am UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/8 "2018-10-17T09:26:57Z")

</div>

@Craig

try to replace

```auto
 {% elif column.content_type == 'form' %}

 {% form form_to_use="{{ module.form.form_id }}" response_response_type="{{ module.form.response_type }}" response_message="{{ module.form.message }}" response_redirect_id="{{ module.form.redirect_id }}" response_redirect_url="{{module.form.redirect_url}}" %}

```

with just a simple

` {% elif column.content_type == 'form' %}{% form %}`

Beside that you can try to replace all of the single quotemarks with double quotemarks. Maybe this is the issue.

Example:

from

` {% if column.content_type == 'rich_text' %}`

to

` {% if column.content_type == "rich_text" %}`

regards,

Anton

---

<div class="post-metadata">

**Author:** ![Craig](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/craig/32/60219_2.png) [@Craig](https://community.hubspot.com/u/Craig)\
**Post date:** [October 17, 2018, 9:45am UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/9 "2018-10-17T09:45:39Z")

</div>

@Anton using

`{% form %} `

means I’m not using the form selector so they won’t get the right form.

And the conditional isn’t the issue (the code within it runs accordingly) - plus ‘rich\_text’ is the same as “rich\_text” when evaluating a string.

---

<div class="post-metadata">

**Author:** ![tjoyce](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/tjoyce/32/88832_2.png) [@tjoyce](https://community.hubspot.com/u/tjoyce)\
**Post date:** [October 17, 2018, 11:53am UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/10 "2018-10-17T11:53:58Z")

</div>

@Craig, @Anton - This could be a bonafied bug in HubSpot. They quietly overnight pushed out major updates to their form code about 3 weeks ago. Try using an embed code and not the module, just to see if you get better results. It might help you narrow down the issue.

I’m getting the same results as @Anton, I created a simple module with a textfield that I can add the form id and then did

`{% form form_to_use="{{ module.formid }}" %}`

The only difference being that you must have your custom fields grouped because @Craig, you are calling module. **form**.form\_id. It’s the only thing i see that stands out.

---

<div class="post-metadata">

**Author:** ![Craig](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/craig/32/60219_2.png) [@Craig](https://community.hubspot.com/u/Craig)\
**Post date:** [October 17, 2018, 1:01pm UTC](https://community.hubspot.com/t/display-form-via-form-selector-in-custom-module/10576/11 "2018-10-17T13:01:07Z")

</div>

@tjoyce it was the nesting, well spotted.

I was correctly grabbing the form ID originally, and for whatever reason it didn’t work - probably error in adding the string within the HubL.

But when I updated the code which added the string ID correctly, I had

`module.form.form_id`

rather than

`column.form.form_id`

Updated to the above and it works.

Thanks all for the help!
