In this tutorial, we'll create public survey pages to gather survey data. Public page means users can use the page without signing in.

We will create super simple survey model with two fields - name and date.

And our response model has survey_id field and response to question about global warming.

We're keeping things simple because the focus of this tutorial is URL generation. All the other details are specific to user needs.

Let's create the page where we'll collect survey responses. We'll generate this page's URL to share with users. In this page, we'll add free form component.

After creating this form, connect it to survey response model.

Okay, we have our response form now. There is still work to do on this form but let's create survey table first. We'll get back to this.

Now, let's add URL column to the table.

This column does not have corresponding field in the model. It doesn't need one. Let's configure this column to generate URL.

Click on the URL column and toggle format text. Then, write this in format text input.

https://code2tutorial-szqj.code2.dev/p/main.htm#/d3-pages/L1lGOWi25a?survey_id={survey_id}

That's survey response page's link:

We added {survey_id} at the end as page parameter. This where the actual "url generation" happens. It gets the survey_id value from our survey model. We'll use that id in the response page.

Let's create some survey records and see the result.

Now, let's get back to response page and use the survey_id in the link. We'll get the survey_id from the link and set form field value.

Click on survey response form and add this event.

Here we're using javascript to extract survey_id from the link and set it to survey_id form field's value. The JS code:

function getParameterByName(name, url = window.location.href) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
return getParameterByName('survey_id');

That's it!

Did this answer your question?