<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Getting form field on form submit in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/317405#M30403</link>
    <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/118763"&gt;@solsen&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ahh, I believe we would need to include &lt;EM&gt;.val()&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;script&amp;gt;
	hbspt.forms.create({
		portalId: "my_portal_id",
		formId: "my_form_id",
		onFormSubmit: function($form){
			if($('input[value="my_field_name"]').val() === 'No'){
				callStripe();
			}
		}
	});
&amp;lt;/script&amp;gt;&lt;/PRE&gt;
&lt;P&gt;I have tested this out on my end using the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; &amp;lt;script&amp;gt;
   hbspt.forms.create({
     css: '',
     portalId: '{{myPortalId}}',
     formId: '{{myFormId}}',
     onFormSubmit: function($form) {
         if(   $('input[name="stringtest"]').val() === 'test' ) {
           alert('hello');
            $('input[name="stringtest"]').val("kitkat2").change();
         }
     }
   });
 &amp;lt;/script&amp;gt;&lt;/PRE&gt;
&lt;P&gt;This works just fine. Could you try and see if this works for you?&lt;/P&gt;</description>
    <pubDate>Fri, 07 Feb 2020 01:47:30 GMT</pubDate>
    <dc:creator>WendyGoh</dc:creator>
    <dc:date>2020-02-07T01:47:30Z</dc:date>
    <item>
      <title>Getting form field on form submit</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/316974#M30343</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to Javascript but want to do the following: on form submit, if a certain field in my form is "No", redirect them to a Stripe checkout page. I have it working with onFormSubmit, but I don't know how to get the field so that I can show the checkout page conditionally based on the value of the form field. Here is what I have so far:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&amp;lt;script&amp;gt;
	window.addEventListener('message', event =&amp;gt; {
	   if(event.data.type === 'hsFormCallback' &amp;amp;&amp;amp; event.data.eventName === 'onFormSubmit') {
	       callStripe('my_sku');
	   }
	});
&amp;lt;/script&amp;gt;&lt;/PRE&gt;&lt;P&gt;From here I would just want to add an if statement along the lines of "if(formFieldValue === 'No') { callStripe(); }. How can I grab the value of a form field for the form that has just been submitted?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 16:24:44 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/316974#M30343</guid>
      <dc:creator>solsen</dc:creator>
      <dc:date>2020-02-05T16:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Getting form field on form submit</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/317128#M30361</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/118763"&gt;@solsen&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When looking to grab the value of a form field from the form, you can use the following code:&lt;/P&gt;
&lt;PRE&gt;$('input[value="{{formFieldValue}}"]')&lt;/PRE&gt;
&lt;P&gt;You can learn more about this on our documentation -&amp;nbsp;&lt;A href="https://developers.hubspot.com/manipulating-forms-with-jquery" target="_blank"&gt;Manipulating forms with jQuery&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2020 03:24:43 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/317128#M30361</guid>
      <dc:creator>WendyGoh</dc:creator>
      <dc:date>2020-02-06T03:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Getting form field on form submit</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/317339#M30395</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/66274"&gt;@WendyGoh&lt;/a&gt;&amp;nbsp;- thanks for the quick response. I think I am close, but could you let me know what I'm doing wrong when testing for the field's value here?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;&amp;lt;script&amp;gt;
	hbspt.forms.create({
		portalId: "my_portal_id",
		formId: "my_form_id",
		onFormSubmit: function($form){
			if($('input[value="my_field_name"]') === 'No'){
				callStripe();
			}
		}
	});
&amp;lt;/script&amp;gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Feb 2020 19:44:37 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/317339#M30395</guid>
      <dc:creator>solsen</dc:creator>
      <dc:date>2020-02-06T19:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: Getting form field on form submit</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/317405#M30403</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/118763"&gt;@solsen&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ahh, I believe we would need to include &lt;EM&gt;.val()&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;lt;script&amp;gt;
	hbspt.forms.create({
		portalId: "my_portal_id",
		formId: "my_form_id",
		onFormSubmit: function($form){
			if($('input[value="my_field_name"]').val() === 'No'){
				callStripe();
			}
		}
	});
&amp;lt;/script&amp;gt;&lt;/PRE&gt;
&lt;P&gt;I have tested this out on my end using the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; &amp;lt;script&amp;gt;
   hbspt.forms.create({
     css: '',
     portalId: '{{myPortalId}}',
     formId: '{{myFormId}}',
     onFormSubmit: function($form) {
         if(   $('input[name="stringtest"]').val() === 'test' ) {
           alert('hello');
            $('input[name="stringtest"]').val("kitkat2").change();
         }
     }
   });
 &amp;lt;/script&amp;gt;&lt;/PRE&gt;
&lt;P&gt;This works just fine. Could you try and see if this works for you?&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 01:47:30 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/317405#M30403</guid>
      <dc:creator>WendyGoh</dc:creator>
      <dc:date>2020-02-07T01:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Getting form field on form submit</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/317421#M30409</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/66274"&gt;@WendyGoh&lt;/a&gt;&amp;nbsp;- thanks for the follow-up! Strangely enough, I was not able to get the values for any of my form fields that way - they all simply returned "undefined". I found a workaround using the .serialize() function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;hbspt.forms.create({
	portalId: "my_portal_id",
	formId: "my_form_id",
	onFormSubmit: function($form){
		var formData = $form.serialize();
		var fieldName = "my_field_name";
		var fieldPosition = formData.search(fieldName);

		if(formData[fieldPosition + fieldName.length+1] === 'N'){ //for "No"
			callStripe();
		}
		else{
			window.open("other_page");
		}
	}
});&lt;/PRE&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 06:48:55 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Getting-form-field-on-form-submit/m-p/317421#M30409</guid>
      <dc:creator>solsen</dc:creator>
      <dc:date>2020-02-07T06:48:55Z</dc:date>
    </item>
  </channel>
</rss>

