Forum

Thread tagged as: Problem, Forms

Perch content not rendering inside form template error and success tags

I want the success and general error messages for a contact form to be editable.

I followed the instructions outlined in https://forum.grabaperch.com/forum/05-25-2017-perch-content-doesnt-work-within-perch-member-form.

I created two regions 'General Error' and 'Thank you' and set them as variables for use in the contact form (See 1 and 2 below). However what happens is the contents of the variables are compiled above the form and not inside the perch:error or perch:success tags.

If i use perch_content() instead of perch_content_custom() inside PerchSystem::set_var() then nothing is shown.

Can you please explain what I am doing wrong.

1) contact.php

<?php 

    perch_content_create('General Error', array(
        'template' => 'general-error.html',
    ));
    perch_content_create('Thank you', array(
        'template' => 'thank-you.html',
    ));
?> 

...

<?php PerchSystem::set_var('general_error', perch_content_custom('General Error', true)); ?>
<?php PerchSystem::set_var('thankyou', perch_content_custom('Thank you', true)); ?>
<?php perch_form('contact.html'); ?>
...

2) cms/templates/forms/contact.html

...

<perch:form id="contact" method="post" app="perch_forms" class="c-contact-form">
    <header class="c-contact-form__header">
        <h1 class="c-contact-form__heading">Make an enquiry</h1>
        <perch:error for="all" type="general">
            <p class="c-contact-form__error"><perch:content id="general_error" /></p>
        </perch:error>

        <perch:success>
          <p class="c-contact-form__success"><perch:content id="thankyou" /></p>
        </perch:success>
.....
Neal Hanson

Neal Hanson 0 points

  • 2 years ago
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Hello Neal,

Since you're using perch_form(), the namespace you need to use is perch:forms not perch:content:

<perch:forms id="thankyou" type="hidden" />

I tried using perch:form and perch:forms. Neither works. Also the perch documentation uses perch:content inside the perch success tag (https://docs.grabaperch.com/templates/form/success/).

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

You also need to fix your perch_content_custom(). It's missing an argument:

PerchSystem::set_var('thankyou', perch_content_custom('Thank you', [], true));
Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

Also the perch documentation uses perch:content inside the perch success tag

Neither me nor the documentation is wrong. A from <perch:form></perch:form> is part of core Perch (i.e. not part of the Forms app).

You can add forms in many contexts: content region (perch:content namespace), blog post (perch:blog namespace), shop product/cart/etc (perch:shop namespace).

What determines what app handles the form submissions is the app attribute. So app="perch_forms" would let the Perch Forms app handle the submissions.

If you add the form in a content region using perch_content() or perch_content_custom(), you would use the perch:content namespace like the documentation. That section of the documentation you linked to isn't specific to the Forms app.

If you add the form to the page with the perch_form() function, you are in a different namespace. You would need to use the perch:forms namespace.

ok. this all works now. Thanks for the tips.