PHP Classes

File: example_tinymce.php

Recommend this page to a friend!
  Classes of Thiemo Kreuz   TM::Apeform   example_tinymce.php   Download  
File: example_tinymce.php
Role: Example script
Content type: text/plain
Description: How to use TinyMCE instead of a textarea
Class: TM::Apeform
A very abstract web form builder and processor
Author: By
Last change: TinyMCE example added
Date: 14 years ago
Size: 2,827 bytes


Class file image Download

 * A slightly complex TM::Apeform and TinyMCE example. You need at least the
 * TinyMCE main package somewhere on your web server. Change the define below
 * and set the directory to where you have copied the package.
 * @author Thiemo Mättig (

define("TINYMCE_SRC", "tiny_mce/tiny_mce.js");


// Create a new form with predefined maxlength and size for all form elements.
$form = new Apeform(255, 80);

// We don't want quotes in the preview. Use mysql_real_escape_string() instead!
$form->magicQuotes = false;

$caption = $form->text("Caption", "No HTML allowed");
if (empty(
$form->error("Please enter a caption");

$categories = array(
$category_id = $form->select("Category", "", $categories);

// Create a textarea with no help text, no default value and 10 lines.
$text = $form->textarea("Text", "", "", 10);
if (empty(
$form->error("Please enter some text");
// We need the internal name of this form element for TinyMCE.
$text_name = $form->getName();

// Add a second textarea. Only the first one should be modified by TinyMCE.
$abstract = $form->textarea("Abstract", "No HTML allowed");

// Add two buttons in a single row.
$submit = $form->submit("Preview|Save");

// Everything is prepared, now we are ready to start the output.

<title>How to use the TM::Apeform PHP Class with TinyMCE</title>
<style type="text/css">
/* A little bit of CSS for a nice preview. */
    background: #EEE;
    border: 1px solid #CCC;
    color: #111;
    font-family: Verdana, sans-serif;
    padding: 1em;
.article h2{
    margin: 0;
    color: #666;
    font-size: smaller;
    margin: 0;
<script type="text/javascript" src="<?php echo TINYMCE_SRC; ?>"></script>
<script type="text/javascript">
        /* The mode "textareas" modifies all textareas. */
        mode : "exact",
        /* Modify the textarea with this name only. */
        elements : "<?php echo $text_name; ?>",
        theme : "simple",

<h1>How to use the TM::Apeform PHP Class with TinyMCE</h1>


// If the save button was pressed, do not display the form and the preview.
if ($form->isValid() && $submit == "Save")
"The text is not saved in this example script.";

    if (
"<div class=\"article\">";
"<h2>" . htmlspecialchars($caption) . "</h2>";
"<p class=\"category\">Posted in " . htmlspecialchars($categories[$category_id]) . "</p>";