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

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
Simon66
Forum Members
Forum Members
Posts: 248
Joined: Wed Aug 29, 2007 4:36 am
Location: Sydney Australia

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

Post 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.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3366
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

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

Post by velden »

Thanks for sharing
Post Reply

Return to “Tips and Tricks”