Forum

Thread tagged as: Question, Forms, CKEditor

Manage Perch Forms content through CMS

Hi,

So the website in question features a form. Currently, this form is pulled in using a html template (using the Perch Forms App). Inside the html template file, there is some text, e.g. "This form collects the following data...". My client would like to be able to update this content in the future through the CMS - is there a way to do this, ideally using a WYSIWYG editor like CKEditor? As obviously this does not exist in a content region, but a forms template.

Thanks for any help!

Matthew Lymer

Matthew Lymer 1 points

  • 6 months ago
Hussein Al Hammad

Hussein Al Hammad 103 points
Registered Developer

Hi Matthew,

You can have a form in a content region.

What determines which app handles the form is the app attribute on the form tag <perch:form app="perch_forms" ... >.

Hi Matthew,

I think you can add an intro field into your form template like this:

<perch:content id="intro" type="textarea" label="Intro" textile editor="markitup" size="m">

And then you'd just drop that copy into the field that appears in the region where you form is.

Hope that helps.

Thanks guys. I think John Robinson's suggestion of adding a content tag into the form HTML will be the best route for me. I just wondered how it then gets added to the CMS?

Do I have to create a new content region and make it shared? (As my form is available on all pages). And if I do, do I use the forms HTML template as the new region's template?

Hi Matthew,

It appears in the content region where your form is, so if you open that once the field is added to the template it should be in there.

John.

Hi John,

But my form doesn't appear in a content region. It is called with perch_form('contact.html') not something like perch_content('contact').

And so I wanted a solution that allows me to keep calling it with perch_form('contact.html') - if not, then I'm not sure how to use perch_content to pull a forms template...

Hussein Al Hammad

Hussein Al Hammad 103 points
Registered Developer

You can have your entire form in a content region and still have the Perch Forms app handle the submission.

So you can have a content template content/contact.html that includes the exact same form. As long as the app attribute on the form tag is app="perch_forms", the Forms app will still handle the submissions.

Inside the content template you can include any perch:content fields you want.

Ah ok, sorry Matthew I've not used this approach. I normally add a form as part of a content region so I'm not sure where you'd access that field in Perch admin with your approach. Sorry I misunderstood what you were looking for. Maybe someone else on here could help?

No worries John.

Thanks Hussein. I'll give that a try - it's just going to take a little longer than I planned (as the website has many forms, none of which are pulled in as perch_content blocks).

Hussein Al Hammad

Hussein Al Hammad 103 points
Registered Developer

The alternative is to add a separate region on the page, have it returned instead of echoed (assuming you require a single field), then pass it to the form's template with a variable.

$form_content = perch_content('Form Intro', true);
PerchSystem::set_var('form_content', $form_content);
perch_form('contact.html');

And in the form template you can render form_content like so:

<perch:if exists="form_content">
<perch:forms id="form_content" html />
</perch:if>

I think having everything in a single content region makes it easier and less error prone.

Hi Hussein,

So I've done what you suggested, and this is a simple version of my form

<perch:form id="contact" method="post" app="perch_forms">
    <perch:input type="email" id="email" required="true" label="Email" />
    <perch:input type="submit" id="submit" />
    <perch:content id="gdpr" type="text" label="GDPR Text" size="xl">
</perch:form>

I moved a copy of the template html into /perch/content/, added a new region, and set that template to the region. I can successfully edit the gdpr field in the CMS, but it doesn't show up on the live page...

However, I didn't know you could pass variables to forms - that is definitely the ideal solution! Thanks!

Hussein Al Hammad

Hussein Al Hammad 103 points
Registered Developer

I can successfully edit the gdpr field in the CMS, but it doesn't show up on the live page..

What version of Perch are you using? If it's older than 3.1, your content tag needs to be self-closed:

<perch:content id="gdpr" type="text" label="GDPR Text" size="xl" />

Ah, my bad. Ultimately then either transferring things into a perch_content region or adding a variable will work. In future I think I'll set things up as perch_content regions - but in the interest of speed and allowing the same content to be shared across many templates, I'll go with the variable solutin.

Thanks!