Prefill form with different info from different buttons

Hi all - I know this is a wix studio forum, but Noah was so helpful with me last time, I think I’ll try to push my luck even further, even though I’m using the regular web-based wix editor.

I have a form, which includes a dropdown menu. There are multiple buttons on the site that will lead to this form. Is it possible to have the dropdown menu prefilled with a selection based on which button a user pressed to end up on the form page?

The use case: we’re a band, and i’m desiging a site for booking corporate events, weddings, etc. I’d like to keep the same form for all entries, but if a user came to the form from the CTA on the weddings page, for example, I’d like the dropdown in the form to already have “wedding” selected as the event type.

Thanks :folded_hands:

Happy to have been of help! :smiley:

I have a demo example which covers much of what you’re looking for here:

What would change from the demo:

  • Instead of a hidden field, it would be the dropdown value you’re setting
  • You will need to set the query param, something like ?eventType=wedding ?eventType=corporate etc. when someone clicks on a link to the page containing the form so you can track which page they came from

THanks Noah! I will check out that demo. Glad to here this is possible :slight_smile:

Noah, if you’ll indulge me a bit more, I’d appreciate it -

On my ‘weddings’ page, I’ve updated the button link to: http://www.merlotembargo.com/quote?eventType=wedding
(Seems slightly safer to assign a page within wix rather than a URL, but I don’t see a way to attach that eventType parameter if I do it that way.)

I’ve pasted your code onto my quote page, and updated the parameters to match the elements on my page. (I think I’ve got them all, but I’m not a web guy at all, or coder of any sort, so bear with me. Also, it doesn’t work anyway, and as i note below, wix seems to have some issues with my parameters anyway.)

});
$w.onReady(function () {
    $w("#dropdown1").onReady(() => {
        let itemObj = $w("#dropdown1").getCurrentItem();

        let currentPage = itemObj["eventType"];

        $w("#multiStepForm1").setFieldValues({
            page_submitted: currentPage
        });
    });
});

When I hover over the onReady in the second line, wix tells me this property does not exist on type "dropdown. Similar red error message when I hover over getCurrentItem. Do i need to declare these at the top of the code or something,

Please forgive my ignorance!
TIA
G

Keep the questions coming - exactly what the community is here for :flexed_biceps:


I see the form uses the older forms, so the code will look a little different, but that’s okay!

Replace all of your code on the page with this (if you get a red line under the @wix/site-location, hover over it and click “install” - it’s just a small code package from Wix that helps with working with URLs.

import * as wixSiteLocation from '@wix/site-location';

$w.onReady(async function () {
    // 1. Get the 'query' object from the URL
    /** @type {Object<string, any>} */
    const query = await wixSiteLocation.location.query();

    // The editor will no longer flag eventType as an error
    if (query.eventType) {
        $w("#dropdown1").value = query.eventType;
    }
});

The final step is to choose the dropdown> Manage choices> and then edit each of the choices so that their value is in camelCase - these are what will be in the URLs.


You’ll then be able to use:

This is fantastic, thanks so much Noah! Works perfectly.

Now, to finish the site…lol