Passing dynamic value to a Contact form to fetch the record

JDoddapaneni
Participant

Could some please help me figure out how should I be passing a dynamic value for the email address in this piece of code: 

{% set contacts = crm_objects("contact","email=test@test.com","firstname,email,lastname,phone") %}

 

This line of code is a part of the following script which is being used to populate a Contact form with the known field values . I am using the email address to pull the reacord. The code is working fine when I am passing a static email address (I pass test@test.com in the form and click the button, it pulls the field values for the First Name, Last Name and the Phone Number). But I want to pass a dynamic email address instead of static. Could anyone help me figure out how?

 

Here is the code:

 

hbspt.forms.create({
portalId: "411995",
formId: "cbf0cb99-b573-4fb3-9f2d-38a1c834d867",
onFormReady: function($form) {
$form.find('#email-cbf0cb99-b573-4fb3-9f2d-38a1c834d867').bind( "change", function() {
var email_value=$form.find('#email-cbf0cb99-b573-4fb3-9f2d-38a1c834d867').val();
console.log(email_value);
console.log('contact email: '+'{{contact.email}}');
console.log('event attribute:'+$(this).val());
console.log('email string:'+'{{ string_var }}');
console.log('on change email called');
{% set contacts = crm_objects("contact","email=test@test.com","firstname,email,lastname,phone") %}

{%for data in contacts.results %}
console.log('{{ data.email }}');
console.log('{{ data.lastname }}');
console.log('{{ data.firstname }}');
console.log('{{ data.phone }}');
$form.find('input[name="lastname"]').val('{{data.lastname}}').change();
$form.find('input[name="firstname"]').val('{{data.firstname}}').change();
$form.find('input[name="phone"]').val('{{data.phone}}').change();
{% endfor %}


{% set contacts = crm_objects("contact", "email= %} $form.find('#email-cbf0cb99-b573-4fb3-9f2d-38a1c834d867').value() {%","name,email,lastname") %}
{%for data in contacts.results %}
console.log('{{ data.email }}');

{% endfor %}

 

 

Thanks a lot in advance!

 

0 Upvotes
1 Accepted solution
Teun
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Hi @JDoddapaneni ,

 

Check this out: https://knowledge.hubspot.com/forms/form-fields-pre-populated-with-your-own-or-someone-else-s-inform...



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


View solution in original post

4 Replies 4
Teun
Solution
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Hi @JDoddapaneni ,

 

Check this out: https://knowledge.hubspot.com/forms/form-fields-pre-populated-with-your-own-or-someone-else-s-inform...



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


JDoddapaneni
Participant

Hi @Teun ,

Thank you for the resource..  I will update you if this works.

0 Upvotes
Teun
Recognized Expert | Elite Partner
Recognized Expert | Elite Partner

Hi @JDoddapaneni ,

 

What are you trying to achieve? Might help to come up with a solution.
Is the prefill functionality not working?



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


0 Upvotes
JDoddapaneni
Participant

Hi @Teun ,

 

Thank you for the response.

 

We are using a contact form but handling a customization based on a Custom object property. We are not a Operations Hub member so could not use custom code for this purpose. It could have been easier with the custom code is what I heard from our Hubspot Rep. So, we found this approach to work on the development we want on the form.  After we built the first part, we have another requirement that wants us to auto populate the form fields with the known Contact field values using the email address of the contact to fetch the record. This is where I am stuck. I am able to pull the record details when I pass a static email address in the code and pass the same email address on the form. But, ideally I should be able to pass the email address dynamically.

Hope this makes sense.

 

And I am new to Hubspot and do not know about the Prefill functionality that you mentioned.

 

Thanks,

Jhansi

 

0 Upvotes