CMS Development

sdeveloper
Participant

Field Value on Form Submit

SOLVE

Hi everyone,

 

I'm trying to create a custom form module that takes the input and calls an API with the information given in the form on submit. I've embedded the code from the form builder, but I'm not sure how to retrieve that values of the inputs. 

 

A previous post suggested something along the lines of 

hbspt.forms.create({
		portalId: "my_portal_id",
		formId: "my_form_id",
		onFormSubmit: function($form){
			if($('input[value="my_field_name"]').val() === 'No'){

 I'm not sure how they got value="my_field_name", because I don't know what the name of each form field is.

Essentially I want to store every input in each form field into a javascript variable.

 

Any help would be appreciated, I'm not sure if this is a trivial question or not..

0 Upvotes
1 Accepted solution
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Field Value on Form Submit

SOLVE

Hi @sdeveloper

 

The format you are showing is selecting a DOM input element with that specific value.

When you do:

 

$('input[value="{{formFieldValue}}"]')

 

This would select a form field where the user had literally entered "{{formFieldValue}}". If you are instead trying to grab a specific form field regardless of what the value is, to test the value against other possibilities, then you would do something like this:

 

$form.find('input[name="{{Internal-Property-ID}}"]').val()

 

Where {{Internal-Property-ID}} is replaced with the internal id of the property on the form. Which you can find in the form builder by looking for the italicized text:

Screenshot 2021-07-21 085303.png

So if I wanted to grab the value of that field, from within the onFormSubmit function, I would use:

 

$form.find('input[name="dummy_text_field"]').val()

 

Also note the use of $form rather than $, as to only search the specific form rather than the entire page.

 

 

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk

View solution in original post

2 Replies 2
sdeveloper
Participant

Field Value on Form Submit

SOLVE
$('input[value="{{formFieldValue}}"]')

I've read that this is the format to follow, but how do I know what to put in formFieldValue? 

0 Upvotes
JBeatty
Solution
Guide | Diamond Partner
Guide | Diamond Partner

Field Value on Form Submit

SOLVE

Hi @sdeveloper

 

The format you are showing is selecting a DOM input element with that specific value.

When you do:

 

$('input[value="{{formFieldValue}}"]')

 

This would select a form field where the user had literally entered "{{formFieldValue}}". If you are instead trying to grab a specific form field regardless of what the value is, to test the value against other possibilities, then you would do something like this:

 

$form.find('input[name="{{Internal-Property-ID}}"]').val()

 

Where {{Internal-Property-ID}} is replaced with the internal id of the property on the form. Which you can find in the form builder by looking for the italicized text:

Screenshot 2021-07-21 085303.png

So if I wanted to grab the value of that field, from within the onFormSubmit function, I would use:

 

$form.find('input[name="dummy_text_field"]').val()

 

Also note the use of $form rather than $, as to only search the specific form rather than the entire page.

 

 

✔️ Was I able to help answer your question? Help the community by marking it as a solution.

Joshua Beatty
Software Developer with Pearagon

Still have questions? Let's Talk