Page 1 of 1

How to autofill fields, from internal links, in a CGBetterForms form

Posted: Sat Apr 03, 2021 10:42 am
by Simon66
So, I needed to automatically fill the subject field of a form, from an enquiry link on a 'Pricing' page.
The 'Pricing' page was populated from a LISE module.
Pricing page with enquiry links.
Pricing page with enquiry links.

The form field to be auto filled:

Code: Select all

        <div class="form-group mt-10">
            <label for="mysubject"><span>Subject</span><i class="fal fa-question"></i></label>
            <input type="text" name="mysubject" id="mysubject" placeholder="Subject" required/>
        </div>

I created the link in the LISE template including the info I wanted in the subject field of the form:

Code: Select all

<a href="{cms_selflink href="contact"}&subject={$item->title|escape:url} at {$item->price_text}{$item->price}" class="site-btn">Submit Enquiry</a>

Then in the CGBetterForms form 'Pre-render Logic' field I added:

Code: Select all

{cgbf_set key=mysubject value={$smarty.get.subject|unescape} }

Now each enquiry link automatically fills the 'Subject' field of the contact form.
Form with subject field automatically filled.
Form with subject field automatically filled.

Re: How to autofill fields, from internal links, in a CGBetterForms form

Posted: Sat Apr 10, 2021 11:09 am
by velden
Thanks for sharing