Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Contact form with dropdowns and radio buttons

This is how a contact form with select dropdown and radio buttons may look like.

<txp:zem_contact_text label="Full Name" name="Name" required="1" min="2" max="40" /><br />
<txp:zem_contact_email required="1" /><br />
<txp:zem_contact_text label="Phone (optional)" min=7 max=15 required="0" /><br />

<txp:zem_contact_text label="Building Address" name="Name" required="1" min="2" max="60" /><br />
<txp:zem_contact_text label="Unit #" name="Name" required="1" min="2" max="40" /><br />

<txp:zem_contact_select break="br" label="Pets" list="None, Cat, Dog, Other" /><br />


<txp:zem_contact_select break="br" label="What needs fixed?" list="Bedroom, Bathroom, Kitchen, Dining Room, Living Room, Outdoor Area" /><br />

<txp:zem_contact_textarea label="Description goes here" cols="40" rows="10"  /><br />

Check off one of the following;<br />
<txp:zem_contact_checkbox label="I give permission for maintenance to enter my unit." required="0" /><br />
<txp:zem_contact_checkbox label="Please call to set up time for maintenance to enter my unit" required="0" /><br />

<txp:zem_contact_submit label="Submit" />



And then simply insert the following into an article
<txp:zem_contact to="email@email.com" form="form_name" />

Subpage Listing Form and Page Template

how to show subpages/secondary pages for a section in the sidebar

<li><a href="<txp:permlink />"><txp:title /></a></li>



and this is the page template
     <txp:if_section name="home">
       <h2 class="subpage"><txp:section title="1" /></h2>
       <ul id="subpage"><txp:article_custom section="home" form="subpagelist" sort="Title asc" />
       </ul>
     </txp:if_section>

Horizontal Navigation

how to build horizontal navigation
<div id="nav">

    <ul id="navlist">

<txp:section name="home" link="1" title="1" wraptag="li" />
<txp:section name="about" link="1" title="1" wraptag="li" />
<txp:section name="portfolio" link="1" title="1" wraptag="li" />
<txp:section name="packages" link="1" title="1" wraptag="li" />
<txp:section name="clientlogin" link="1" title="1" wraptag="li" />
<txp:section name="contact" link="1" title="1" wraptag="li" />
  </ul>
</div><!-- end nav-->

Meta Form

Meta form

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<txp:css format="link" media="all" />

<!-- Meta Tags -->
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<meta name="robots" content="index, follow" />

<title>Website Title Goes Here | <txp:page_title /></title>

<meta name="description" content="description here" />
<meta name="keywords" content="description" />


<!-- Favicon -->
<link rel="shortcut icon" href="" />

<!-- RSS -->

<link rel="alternate" href="" title="RSS Feed" type="application/rss+xml" />

</head>

Excerpt from article

// Useful form if you want to know how to pull an excerpt of an article onto an existing article/webpage

<h1><txp:title /></h1>
<txp:excerpt />
				
<p class="moreinfo"><txp:permlink>##more_info##</txp:permlink></p>

sitemap

// Sitemap Form that will show the Section title and the list of articles for that section.

<txp:if_article_section name="sitemap">

<txp:else />
<txp:if_different>


   </ul><h2><txp:section title="1" /></h2><ul>

</txp:if_different>

   <li><txp:permlink><txp:title /></txp:permlink></li> 

</txp:if_article_section>


// Sitemap Page template looks like this;

     <div id="content">
<h1>Sitemap</h1>
<ul style="display:none;"><txp:article_custom limit="99999" form="sitemap" sort="section asc,Posted asc" /></ul>	

    </div><!-- content -->	

if section

// how to get a particular list of articles to show up on the sidebar if they land on that particular section.

   <txp:if_section name="about">
      <ul id="subpage">
     <txp:article_custom section="about" sort="Title asc" form="subpage_listing" />
      </ul>
   </txp:if_section>


// and this is how the form looks like;

<li><a href="<txp:permlink />"><txp:title /></a></li>

Zem_event_display form

// form used to display events from the GDPN site.

<dl>

<dt>Starts:</dt>
<txp:chh_if_data>
  <txp:zem_event_date wraptag="dd" />
<txp:else />
  <dd>To be confirmed</dd>
</txp:chh_if_data>

<txp:chh_if_data>
  <dt>Ends:</dt>
    <txp:zem_event_finish_date wraptag="dd" />
</txp:chh_if_data>

<dt>Time</dt>
  <dd>from <txp:zem_event_time format="%I:%M %p" /><txp:chh_if_data> to <txp:zem_event_finish_time format="%I:%M %p" /></txp:chh_if_data></dd>

<dt>Location</dt>
<txp:chh_if_data>
   <txp:zem_event_location wraptag="dd" />
<txp:else />
   <dd>To be confirmed</dd>
</txp:chh_if_data>

<txp:chh_if_data>
<dt>Categories</dt>
  <dd><txp:zem_event_categories break=", " link="0" section="events" /></dd>
</txp:chh_if_data>

<txp:chh_if_data>
  <dt>Description</dt>
  <txp:zem_event_description wraptag="dd" />
</txp:chh_if_data>

</dl>

<txp:if_article_list>
            <p class="more-info"><txp:zem_event_permlink>##more_info##</txp:zem_event_permlink></p>
</txp:if_article_list>

Not This Section

// description of your code here

<txp:if_section name="notthissection">
<!-- do nothing -->
<txp:else />
blah blah
</txp:if_section>

Serving links to multilingual pages

http://forum.textpattern.com/viewtopic.php?id=12371

Let’s assume you want to have two sets of pages which would be crosslinked with links like “see this page in [another language]”. Set custom fields for the languages you want to support, name them, for example eng and ukr (for English and Ukrainian).

Write articles for those languages and assign them links of their sibling articles on the other language, say, you have an article in English with permanent link “/about/my-dog” and you have the same article in Ukrainian with permanent link “/about/my-dog-ukr”, then set “/about/my-dog” to the custom field “eng” in the article on Ukrainian and “/about/my-dog-ukr” to the custom field “ukr” in the article on English.

Then in the article form you use write a code similar to the following:

<txp:if_custom_field name=“eng”>
<a href=”<txp:custom_field name=“eng” />”>this page in english</a>
</txp:if_custom_field>

<txp:if_custom_field name=“ukr”>
<a href=”<txp:custom_field name=“ukr” />”>this page in ukrainian</a>
</txp:if_custom_field>


That’s it! When it’s English link to Ukrainian article will be shown up and vice versa.
It’s just a basic example to give you an idea, hope it helps.