External Website Embedding Form

I have a website in which I am embedding the hubspot form. After I submit the form, I want it to go to a link, dependent on if a certain question was answered or not. Is it possible to get a specific question value (to check if it is undefined?)

Is this correct? var testing1Value = response.data.fields.testing1;"

thank you!

Hi @0784

I’ve done this before by creating a Custom Module, which holds a form, that redirects based on values in the form.

The custom module uses the Form Embed Code to set a Javascript function in the onFormSubmit handler and/or setting the redirectUrl.

Usually you will have to make sure the form is an HTML Form (in your Form Settings under Style & Preview tab).

Have fun

Mike

Hello,

I’ve been using this format: I’m not sure about this syntax: var testing1Value = response.getResponse().getField(‘testing’);

<!DOCTYPE html>
<html>
<head>
<meta charset=“UTF-8”>
<title>HubSpot Form with Chart Display</title>
<script charset=“utf-8” type=“text/javascript” src=“//js.hsforms.net/forms/embed/v2.js”></script>
</head>
<body>
<script>
hbspt.forms.create({
//
onFormSubmit: function(response) {
handleFormSubmit(response);
}
});

function handleFormSubmit(response) {
var chartContainer = document.getElementById(‘chartContainer’);
var testing1Value = response.getResponse().getField(‘testing’);

// Display different charts based on the field value
if (testing1Value && testing1Value.trim().length > 0) {
// Chart for answered question
var chartHtml = ‘<iframe src=“https://docs.google.com/spreadsheets/…;headers=false” width=“100%” height=“400”></iframe>’;
chartContainer.innerHTML = chartHtml;
} else {
// Chart for unanswered question
chartContainer.innerHTML = “”; // Clear the chart container if the field is empty
}
}
</script>
<!-- Chart container -->
<div id=“chartContainer”></div>
</body>
</html>