Dynamic Default Values

SOLVE
Highlighted
New Contributor

Hi there,

 

When  I use Wufoo Forms, it's really easy to modify default values

 

Example:

    <script type="text/javascript">var asdasdmj;(function(d, t) {
        var s = d.createElement(t), options = {
        'userName':'myusername',
        'formHash':'zx300',
        'host':'wufoo.com',
        
        'defaultValues':'field34=<?php the_title(); ?>',
        
        };
    </script>



I could not find a solution for Hubspot,
I wish something like this: 

 

<script>
  hbspt.forms.create({
            portalId: "XXXX",
            formId: "XXXX",
            defaultValues: { myfield33 : <?php the_title(); ?>  }
});
</script>

 

or I wish

 

[hubspot type=form portal=111111 id=XXXX my-field-33="mytext"]

 

I have tried this: 

https://developers.hubspot.com/manipulating-forms-with-jquery

https://knowledge.hubspot.com/forms/can-i-auto-populate-form-fields-through-a-query-string

 

Could not find a solution.

 

I don't have an access my client's account. They're just giving shortcode or embeded JS code. Is there anything I can do?

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Highlighted
HubSpot Moderator

Hey @bburak,

 

By modifying the default values do you mean that you'd like to set a form value on the form field when the form loads? 

 

If so, you can do something like this:

 

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
 <script>
   hbspt.forms.create({
     portalId: 'portalId',
     formId: 'formId',
     onFormReady: function($form) {
           $form.find('input[name="stringtest"]').val("kitkat2").change();
     }
   });
 </script>
        {{ standard_footer_includes }}
    </body>
</html>
2 Replies 2
Highlighted
HubSpot Moderator

Hey @bburak,

 

By modifying the default values do you mean that you'd like to set a form value on the form field when the form loads? 

 

If so, you can do something like this:

 

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
 <script>
   hbspt.forms.create({
     portalId: 'portalId',
     formId: 'formId',
     onFormReady: function($form) {
           $form.find('input[name="stringtest"]').val("kitkat2").change();
     }
   });
 </script>
        {{ standard_footer_includes }}
    </body>
</html>
Highlighted
New Contributor

Thank you. 
That's the what I want.

Reply
0 Upvotes