Capture the dynamic page on which a CMS form was filled

I have a CMS form on a dynamic page. When users submit the form, I cannot tell which page they filled it on. I want to write a code that would help me automatically fill out a field in the CMS forms collection from the dynamic page CMS collection, so that I can see which dynamic page the user submitted a response to.

Can you help me with this?

Thank you, any help is much appreciated!

I solved it! Wix chatbot helped me with the code and I’m sharing it here:

import wixLocation from 'wix-location';

$w.onReady(function () {
    // Replace 'dynamicDataset' with the actual ID of your dynamic page's dataset
    // Replace 'formDataset' with the actual ID of your form's dataset
    // Replace 'dynamicField' with the field key in the dynamic page's dataset
    // Replace 'formField' with the field key in the form's dataset

    const dynamicDataset = $w("#dynamicDataset");
    const formDataset = $w("#formDataset");

    formDataset.onBeforeSave(() => {
        // Get the value from the dynamic page's dataset
        const dynamicFieldValue = dynamicDataset.getCurrentItem().dynamicField;

        // Set the value in the form's dataset
        formDataset.setFieldValue('formField', dynamicFieldValue);

        return true; // Indicate that the save operation should proceed
    });
});
1 Like

Thank you Ana for the resolution.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

This is just a sentence doing sentence things.