Forum for discussing general topics related to Couch.
4 posts Page 1 of 1
Hi everybody,
first of all, thank you for a great work. I'm working with Couch now for 2 days and it's a great tool. I really enjoy the work with it.

So my problem is...
Client wants a contact form append on every page. So I've created snippet and tried to embed it. BUT I was following the documentation (Contact Form) and there is of course <cms:template title='Contact form'>... which leads to rewrite the "index" title in the admin section. And "append" this form to this "index" page :-/

Is it possible to create contact form like the one in the documentation (with custom editable areas - social etc.), embed it/append it to the page and still have a separate section for this form in admin?

I was searching on the web, in this forum, go through "Tips & Tricks" section ... no luck :-/ I was able to do a lot of things but this one - I'm stuck.

Thanks for any help or point a right direction.
(sorry for my english )

EDIT: I find this topic http://www.couchcms.com/forum/viewtopic.php?f=2&t=7731. I see the contact form in the admin section - good :) But it doesn't show the form on the page. I have this code.
Code: Select all
<cms:pages masterpage='cs/contact-form.php' limit='1'>
</cms:pages>


When I do this:
Code: Select all
<cms:pages masterpage='cs/contact-form.php' limit='1'>
     <cms:show some_field_defined_in_template />
</cms:pages>

It shows the content of this particular field but I don't know how to show the whole template.
Hi and welcome Mishack :)

You are almost there as you already know about all the required concepts (embeds, cms:pages with 'masterpage' parameter).
Let us clear up the few remaining points that seem to be tripping you up and we'll be through.

Your contact.php (as does every template) does *two* distinct things -
1. Defines editable regions (these appear under the template's name in admin-panel).
2. Define the HTML markup used when contact.php is visited on the front-end.

So, if following is a skeletal representation of contact.php, the red part does the first point listed above while the blue does the second -
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Contact'>
<cms:editable name='contact_address' type='textarea' />
</cms:template>


<cms:form>
... form code here..
</cms:form>

<div class='address'>
<cms:show contact_address />
</div>


<?php COUCH::invoke(); ?>

If we cut away the blue part (i.e. the markup) and place it in a snippet (say named my_contact.html) and make the code to follows -
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Contact'>
<cms:editable name='contact_address' type='textarea' />
</cms:template>


<cms:embed 'my_contact.html' />

<?php COUCH::invoke(); ?>

- it'd work *exactly* as the first version.

So, when we embed something, the statement <cms:embed 'some_file.html' /> gets replaced verbatim by the contents of that file. For all practical purposes it is as if the contents were physically present at the place the cms:embed is used.

So what happens if we use the same embed statement we used above in a different template (e.g. blog.php)? e.g. as follows
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Blog'>
<cms:editable name='blog_text' type='richtext' />
</cms:template>


<cms:embed 'my_contact.html' />

<?php COUCH::invoke(); ?>

It gets expanded to become -
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Blog'>
<cms:editable name='blog_text' type='richtext' />
</cms:template>


<cms:form>
... form code here..
</cms:form>

<div class='address'>
<cms:show contact_address />
</div>


<?php COUCH::invoke(); ?>

The parts of the embedded content that have no reference to the original contact.php template (e.g. the FORM above) will function with no problem in blog.php template but consider this part of the content

<div class='address'>
<cms:show contact_address />
</div>
Here we are referencing a region named 'contact_address'.
Obviously this region/variable is present in contact.php and not in blog.php so this prints nothing.

However, if we were to use the embed in blog.php in the following manner -
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Blog'>
<cms:editable name='blog_text' type='richtext' />
</cms:template>



<cms:pages masterpage='contact.php' limit='1'>
<cms:embed 'my_contact.html' />
</cms:pages>


<?php COUCH::invoke(); ?>

It would expand to -
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Blog'>
<cms:editable name='blog_text' type='richtext' />
</cms:template>



<cms:pages masterpage='contact.php' limit='1'>
<cms:form>
... form code here..
</cms:form>

<div class='address'>
<cms:show contact_address />
</div>
</cms:pages>


<?php COUCH::invoke(); ?>

and now the <cms:show contact_address /> can find the 'contact_address' as the cms:pages (courtesy the 'masterpage' parameter set to 'contact.php') fetches all data from contact.php and makes it available within the <cms:pages>..</cms:pages> block.

That is the connection between embed and cms:pages.

To recap -
1. share embeds across templates only for the structural part (i.e. not the part where we define editable regions). The blue portions in the examples above are what we can share.

2. If the embedded content references data from a particular template, we'll have to explicitly fetch in that data using cms:pages tag for the embed to work correctly.

Hope I was able to explain things properly and this helps :)
Thanks for the comprehensive answer. I understand now. Works like a charm :)

I have problem with sending emails now, but it seems to be problem with configuration on my server (I'm using Synology NAS). I did some research here (alternative_mta, direct adresses) and even tried simple form without a cms. I have to test it on a live server. Maybe then I'll be bothering you again :)

Again thank you for a warm welcoming and quick and complex explanation.
You are always welcome, Mishack :)
I am glad my explanation helped.
4 posts Page 1 of 1
cron