Support This Site

Creating a Tag Board Print E-mail
Written by Tim Jones   
Tuesday, 23 November 2004

FacileForms is great for simple forms but its true strength is in its ability to go beyond static forms and enter the realm of applications development. As we will see in this tutorial FacileForms allows you to create Database Tables, Insert information from  a user into tables, and display the results in a form. It also allows you to tap into the powerful Mambo $MainFrame and interact with users and content.

Our task for this tutorial is to create a Tag Board module that can be customized. We will cover page redirection, user rites and access, and data manipulation.

 

 
Requirements

Prerequisites:

I think it is important to have an understanding of these before pressing on. I will not cover simple form and element creation in this tutorial as those were covered in the two items above.

Unlike the Assessment tutorial this will be explained as if we are building this from scratch. It is important to do the tutorial in this manner due to the many different ways the tag board behaves depending on several conditions that exist. For that reason I suggest that you either do the tutorial along with us before downloading the package and installing it. If you just cant wait to download the package and install it I recommend you read this in order to understand how it works.

Now it is important to understand that this is not a standard form, this is a very simple application that exploits PHP pieces, use of hidden elements, and using page redirection to handle different tasks. The concepts displayed here are very basic examples of what can be done with FacileForms. Understanding these concepts will equip you to make more sophisticated applications in the future.

Because we are now dealing with an application rather than a static form a bit of planning is well advised. Knowing what you want your application to do, and breaking that down into small logical tasks to assign FacileForms will insure the end product performs correctly.

Here are the steps I will follow.

  • Define Logic needed to display forms and store data.
  • Creating the Form Pages
  • Adding the PHP and scripts needed
  • Style the module
 
Define Logic
Here is what I want my application to do when the form is displayed on the web page.
 
Check to see if the database for the tags exists (is the Tag Board set up?)
         Yes (Display the tag board ready for use, go to page 1)
         No ( is the user a super administrator, can the user play with your database)
                        Yes (Display a form to create the Tag Board table, set up the Tag board)
                        No (Display a form to the user that the board needs to be setup)            Add a tag (user inputs text, hits post, tag is displayed Page 1)
Make the table (admin sets up tag board Page 2)

Most of the time the module will display page 1 of the form, ready to accept a tag from the user, when the form is submitted it will add a record to the table and display the tag and user in the module.

Creating the Form;

Log in to the admin section of your web site. Using the menu item, Components -> FacileForms -> Manage Forms option open the form manager. Click the New Icon to open a new form and enter the following values in the dialog.

  • Title:               FF Tag Board
  • Name:              tagboard
  • CSS <div>       leave blank for now
  • CSS <form>    leave blank for now
  • Ordering           leave as set
  • Published          Yes
  • Width               100%
  • Height              Auto    Bottom Mar      10px
  • Preview mode Overlay 160px
  • Log to DB        Nonempty values
  • Email                No, You can change this if you like a lot of email.
  • Description       A simple Tag Board made with FacileForms that is meant to be used in a  module.

 
Go ahead and click your save Icon, we will revisit the form in a moment.
 
Now click the page 1 of your new form to start adding elements.

One of the things I learned doing this form was a navigation trick that saves tons of time. Once you have your form created you can bypass switching back to the Manage forms screen while editing pages by clicking the Edit Form Icon from any page you are working on. Give it a try.

Ok Lets define the pages we will need.

  • We need the main page that will allow users to tag the site and see the tags left by others.
  • We need a page for super administrators to use when the module sees no database table.
  • We need a page to inform the every day user that the board has not been set up yet.

So since the busiest and most used page will be the tag page, lets make that page one. You should be looking at an empty page.

Elements for the fist page; Click new from the Mambo and create a Static/Html item.

Our first element is a static text / html element that will need to have the following values

  • Title:               intro
  • Name:             ftb_intro  (it is important to name this exactly)
  • CSS                none at this time
  • Ordering          leave as set
  • Published         Yes
  • Position X        10px, Position Y, 0px
  • Width              0, Height 0
  • Text/Html        Type Tag Click Post
  • you can change the last value to anything you would like to make it fit your site.

 
Save this element  
 
Now we need an element to hold the tag the user will by posting. Click the new icon and from the inputs area choose text, click continue. Enter these values for our tag element
  • Title:                tag
  • Name:             ftb_tag
  • Class <div>      none
  • Class<input>    inputbox (this will pull from your template style sheet)
  • Published          Yes
  • Include log        Yes
  • Pos X               3px      Pos Y   28px
  • Width               130px              Max Length      110
  • Password         No
  • Value               Empty

On important value to note here is the Max Length value. Unless you want folks posting small novels and potentially harmful scripts of size, you need to insure this value is set. You can change it to the value you like. For me I consider 110 characters to be plenty for a tag.

Also since this is the only information we are getting from the user, click the script tab and select the not empty library script for validation. An empty tag is a worthless tag.

Save this element and click New for our next item.

Now we need a button that will act as a form submit button when the form is in use mode. So select Regular button from the buttons section. Click New select reguler button and click continnue

Enter these values for our button.

  • Title:                 Post
  • Name:               ftb_post
  • Class <div>        none
  • Class <input>     none or 'button' as on page 2, to use the site template setting for buttons
  • Ordering            leave as set
  • Published          Yes
  • Position X         50px
  • Position Y         53px
  • Type:              Enabled
  • Label:              Post

Click the scripts tab and set the action script to
Library
on click checked
Script Validate and Submit Form.
 
 
Click the Save button
Your form will now look like this.
 

 

We will add a Query List and Hidden element in a bit. For now we are just laying things out so be patient we will get back to these.
 
Click the Add Page Behind Icon to create our next page. This page will hold the elements needed for the super administrator to create the table to hold our tags if it has not yet been created.
While you are setting at the empty page 2 screen click the New Icon.  Our fist element on the second page needs to hold some instruction for our admin. Select static text/html as the type and click continue. Set the values for this element as follows.
  •  Title:              Make Table
  • Name               ftb_mtabletxt  ( it is important to name this correctly you will see why)
  • CSS <div>        none
  • Ordering           Leave as set
  • Published          Yes
  • Position X         18px
  • Position Y         40px
  • Width              0
  • Height             0
  • Text/html         Administrator click here to set up FTB

Click the save button.

Now we need a second Form Submit button. Now I know that it sounds strange but at this point we are just laying out our pages. All of this will make sense when we start adding logic to our application. So click the new icon  and select Regular button from the button section. Click continue. Add the following values for the new button

  • Title:               Create Table
  • Name               ftb_ctable
  • CSS <div>        none
  • CSS <input>     button
  • Ordering           Leave as set
  • Published         Yes
  • Position X        25
  • Position Y        10
  • Type               Enabled
  • Label               Create Table

Normally we would go set the click action script at this time. As you remember we used the library Validate and Submit form on our first button. We are going to define a custom script for this button a little later. For now just click save.

Your new page 2 now looks like this.

We need one more page to be displayed to users if the board has not been set up. Click the Add Page Behind icon  to create our page 3

We need a single important element on page 3. This is needed so that we can identify this item for directing the page later, not to mention the user needs some information to explain why they can not tag at this time. Click the new icon, and select static text/html as the type and click the continue button.

Set the new static element values like this.

  • Title:                No Table
  • Name               ftb_ntable  ( important name this correctly )
  • CSS <div>         none
  • Ordering           Leave as set
  • Published          Yes
  • Position X         10px
  • Position Y         0px
  • Width               0
  • Height              0
  • Text/html         Facile Forms Tag Board has not been set up at this time. Contact your administrator and tell them you are ready to Tag FF.

 Click the save button.

Now we have the form defined and all the pages needed to accomplish most of our work. If you were to load this into a module at this point you would get nothing more than a form that collected tags from a user and saved them as records with FacileForms.

Not much of a tag board in its current state. So now we call in the logic. Before I dive into the specifics on code and scripts that make this little gem work I would like to clarify a few main points about how code is handled in FF.

 
When you see code in any of the element code sections you are looking at javascript. Javascript is a client side scripting language that runs in the browser of the person looking at the form. While javascript is the sripting lanquage found used in most of the examples in FacileForms it is not the only lanquage used.
 
PHP is a server side language that processes on the server before the web page or form is sent to the browser. PHP can be incorporated in a few ways. The most prevalent is in Pieces. Pieces are PHP blocks that run when one of four things happen.
 
  • Before Form, before a form is loaded.
  • After Form , after a form is created and before it is sent to the browser.
  • Begin Submit, Runs as the first actions of the form submit process.
  • End Submit, Runs at the end of the form submit process.

PHP  can also be embedded into elements on pages.One word of caution, PHP code embedded in a form element, like before/after form pieces, will execute while that form is created on the server. But if you embedd php code between javascript code, you might easy make the error to assume the php code is executed while that javascript function is executed. Not so.

So while this works fine if your trying to populate a drop down list with Mambo Users, it will not work in a conditional statement. One of the road blocks I ran into was trying to set the make table PHP block function in the Click action of the Make Table button. I assumed that if you did that the PHP would only execute when the button was pushed. Not so.
In our example we will use PHP in two pieces of the form. Then use Javascript in the elements to set variables and hidden fields to control the outcome of the Pieces.
Did I loose you? Well lets back up and take it step by step looking at the logic I defined earlier.
 
Logic
Check to see if the database for the tags exists (is the Tag Board set up?)
         Yes (Display the tag board ready for use, go to page 1)
         No ( is the user a super administrator, can the user play with your database)
                        Yes (Display a form to create the Tag Board table, set up the Tag board)
                        No (Display a form to the user that the board needs to be setup)            Add a tag (user inputs text, hits post, tag is displayed Page 1)
Make the table (admin sets up tag board Page 2)
Our first task is to determine if the table that will hold our tags exists. I will use the before form Piece to get this done. If you are where we left off on page 3 simply click the Edit Form Icon from the Mambo tool bar.
Up pops the form all ready to edit. No need to head all the way out to manage forms, nice feature huh? OK, I know, I need to get out more.
Select the Pieces tab and Click the Custom Type in the Before Form section.
 

Now here we head off into coding. Remember I am a real rookie at this and their may be more efficient ways of getting this done. Most of my code is hijacked from other examples or worked out in support forums around the world.

The entire before form custom piece looks like this

// declare our variables and set exists to 0 
global $my, $exists;$exists = 0;
//look through the tables to see if mos_tbd_tags is in the Mambo database.
$dataset = mysql_query('SHOW TABLES') ;
while( $row = mysql_fetch_row($dataset) )
{
if ( $row[0] == "mos_tbd_tags" ) {
$exists = 1;
   break;
}
}
// if it exists got to page 1
if ( $exists == 1 ) {
$this->page = getPageByName($this, 'ftb_intro');
// if it does not exist send the form to the correct page for user type 
 } else {
         if ($my->usertype == "superadministrator") {
             $this->page = getPageByName($this,'ftb_ctable');
         } else {
             $this->page = getPageByName($this,'ftb_ntable');
                }
         }
Lets break down the code and look at how it works and meets our logic model. First item in our logic model is: 
Check to see if the database for the tags exists (is the Tag Board set up?)
here is the code.
 
global $my, $exists; 
 $exists = 0; 
 $dataset = mysql_query('SHOW TABLES') ; 
 while( $row = mysql_fetch_row($dataset) ) 
 { 
 if ( $row[0] == "mos_tbd_tags" ) { 
 $exists = 1; 
    break; 
 } 
 }
 Here is the English version of the above code.
 Declare two variables that can be seen from anywhere called $my and $exists
global $my, $exists;
Set the value of $exists to 0 so that it is assumed the table does not exist unless changed.
$exists = 0;
Load up a variable ($dataset) to hold the names of all the tables in the Mambo Database.
$dataset = mysql_query('SHOW TABLES')
Look at each table name in the $dataset to see if we find mos_tbd_tags (this is the table we will create) If we find the table name then $exists is set to 1, if it is not $exists remains 0.
while( $row = mysql_fetch_row($dataset) )
 { 
 if ( $row[0] == "mos_tbd_tags" ) { 
 $exists = 1; 
 break; 
 }
That is logic element number 1 out of the way. Now that our application has learned whether the table exists or not, If it does $exists is 1 if not it is 0. We now need to take action based on that value. We are now here in our logic.

Check to see if the database for the tags exists (is the Tag Board set up?)

         Yes (Display the tag board ready for use, go to page 1)
 
if ( $exists == 1 ) {
$this->page = getPageByName($this, 'ftb_intro');
} 
This is simple enough, If we find the table in our database, send the user to the page that holds the element ftb_intro. Remember we named our first element on page one ftb_intro. A function looks for that and returns page 1 from the function. This->page then directs our form to page 1 and our users are ready to tag our site. 
 
Great now we go back to our logic model to see what else we have to deal with.
 
Check to see if the database for the tags exists (is the Tag Board set up?)
            Yes (Display the tag board ready for use, go to page 1)
            No ( is the user a super administrator, can the user play with your database)
                       Yes (Display a form to create the Tag Board table, set up the Tag board)
                        No (Display a form to the user that the board needs to be setup)
 

So our table is not set up. Now how do we direct our tag board to the correct page. In the If above we tested for and found the table exists. Since it does not we need to tell our program to go in another direction. A simple  
}else {
Does this for us and then all we left to do is qualify the user type to figure out what page to display. 
Here is the code
        if ($my->usertype == "superadministrator") { 
              $this->page = getPageByName($this,'ftb_ctable'); 
          } else { 
              $this->page = getPageByName($this,'ftb_ntable'); 
                 } 
          }
And in english it is explanined this way.
If I am a super administrator find the page that has an element called ftb_ctable. (ftb_ctable is the first element on page 2)
$this->page = getPageByName($this,'ftb_ctable'); (ftb_ctable is the first element on page 2)
if I am not a superadministrator
} else { 
then go to page three 
$this->page = getPageByName($this,'ftb_ntable'); (ftb_ntable is the first element on page 3)Close the code
                 }
          }
If all this is done correctly when you save it from the admin section you will see the form now displays page 2. This is because our function sees you as a superadministrator and the table does not exist so it directs you to the page to set up the database. To test for users, go ahead and publish this form and add it to a menu link on your site. From the front end log out of Mambo and view your page as a visitor. Click the menu link and you should see page 3.
 
Because you are now no longer a superadministrator and the table does not exist. Cool huh. That simple concept has endless possibilities for developing other applications in FacileForms.
Ok it is time to get back to work.  
Now that we have our form Navigating to the correct page we need to deal with the form submit problem.
 
We are here in our logic.
Check to see if the database for the tags exists (is the Tag Board set up?)
            Yes (Display the tag board ready for use, go to page 1)
            No ( is the user a super administrator, can the user play with your database)
                        Yes (Display a form to create the Tag Board table, set up the Tag board)
                        No (Display a form to the user that the board needs to be setup)           Add a tag (user inputs text, hits post, tag is displayed Page 1)
Make the table (admin sets up tag board Page 2) 

Now we need to deal with the submit process. Here is where we will do a little FacileForms hocus pocus to help our form deal with the fact that we have two submit buttons that need to perform two different actions. Again this is a basic example of a process that can be used in more sophisticated applications. If you learn this process here you can use it again and again.

To help us with this, we are going to create a hidden input element that will hold a value for us. Log back into Mambo as the admin and select Components-> FacileForms -> Manage Forms. From your list of forms click page 1 for the tagboard form.

Click the New Icon on the Mambo Toolbar and add a hidden input element from the element types dialog click continue and give it these values.

  • Title:            ftbtask
  • Name:          ftb_task
  • Ordering:      Leave as default
  • Published      Yes
  • Log              Yes
  • Value           post_tag
 
Click the save Icon.
 
Because you have not created the table and you are a superadmin the preview overlay will continue to display page 2 even though you are editing page one. That is ok that means our before form piece is working correctly. 
 
Now we need to work with our Begin Submit Piece so it will use this element. Click the Edit Form Icon from the Mambo tool bar and select the pieces tab. Go to the Begin Submit area and choose custom to open up our text box for the code.
 
The entire piece looks like this
 
global $database;
global $my;
$user = '';
$post = '';
$task = '';
 
if ($my->username != '')
    $user = $my->username;
else
    $user = 'Visitor';
// extract form data
foreach ($this->submitdata as $data)
    switch ($data[_FF_DATA_NAME
]) {
        case 'ftb_tag':
            $post = $data[_FF_DATA_VALUE
];
            break;
        case 'ftb_task':
            $task = $data[_FF_DATA_VALUE
];
            break;
        default:
            break;
    } // switch

if ($task == 'create_table') {
//make table
$database->setQuery(
    "CREATE TABLE IF NOT EXISTS `#__tbd_tags` (".
        "`postid` INT( 11 ) NOT NULL AUTO_INCREMENT ,".
        "`user` VARCHAR( 50 ) NOT NULL ,".
        "`post` VARCHAR( 100 ) NOT NULL ,".
        "PRIMARY KEY  (`postid`)".
    ") TYPE=MyISAM AUTO_INCREMENT=1"
);
$database->query();
} else {
// make post
$query = "INSERT INTO mos_tbd_tags (user, post) VALUES ('$user', '$post')";
$database->setQuery( $query );
$database->query();
}

Let's break it down. First we will need to define a few variables to work with

global $database;  // this is a global variable that Mambo uses to reference the Mambo Database you use.
global $my;  // A mambo variable that holds current user information
$user = ''; // a variable we will use to identify our user by name
$post = ''; // a variable to hold our tag text that a user tags the site with
$task = '';  // a variable that will tell the pieces what submit process to follow, ie post a tag or create a table.
 
Lets get our user defined using this code
if ($my->username != '')
    $user = $my->username;
else
    $user = 'Visitor';
In english
If the Mambo variable $My is not empty 
 if ($my->username != '')
Then asign asign $user my Mambo user name
 $user = $my->username;
Else assign $user the value of visitor
else
    $user = 'Visitor';
 
Ok now lets grab all the other information from our form. The first few lines tell the piece to check every element in $this form,
// extract form data
foreach ($this->submitdata as $data)
And take the following action when the element name is found.
switch ($data[_FF_DATA_NAME]) {
In the case of ftb_tag set the variable $post equal to the value of ftb_tag[_FF_DATA_VALUE]. The [_FF_DATA_VALUE] simply refers to the value of the element after a user types a tag in it
 
case 'ftb_tag':
        $post = $data[_
FF_DATA_VALUE];
        break;
Now we need to know what task we want the submit action to do, create a form or make a tag. We need to set the value of $task to accomplish this later in our piece so we set it equal to ftb_task (our hidden element),

case 'ftb_task':
            $task = $data[_FF_DATA_VALUE
];
            break;

Since we now know who is submitting the form $user, and if they are making a $post, and what task to perform on the submit process we can move on and close the code that gets all this information from the form.
        default:
            break;
    } // switch
 
Now all we have to do is use the $task variable to tell our submit piece what we want to do.
So if we click the Make Table button on page two of our form it will set the hidden input value, and finally also the $task value to "create_table" then we need to have the submit piece perform the task of creating our table. Here we check for the value.
if ($task == 'create_table') {
 

To make the table we hook to the Mambo Variable $database, and set a query to create a table.
//make table
$database->setQuery(
    "CREATE TABLE IF NOT EXISTS `#__tbd_tags` (".
        "`postid` INT( 11 ) NOT NULL AUTO_INCREMENT ,".
        "`user` VARCHAR( 50 ) NOT NULL ,".
        "`post` VARCHAR( 100 ) NOT NULL ,".
        "PRIMARY KEY  (`postid`)".
    ") TYPE=MyISAM AUTO_INCREMENT=1"
);

Then just have the query execute to finish the process.

$database->query();

If you are not familiar with creating SQL queries such as this do yourself a favor and get access to phpmyadmin and use the SQL query builder to design queries. I use PHPmyadmin on my host cpanel and as the component that can be installed on Mambo from Mambo Forge. Other good ones are MySql administrator found at the MySQL home page, and if you want a full blown GUI for your server, Navicat. It can be downloaded for trial and purchased if you like it. It has a real good query builder that will generate a query for you.
 
Finally if the value of $task is anything other than create_table we ill execute the code needed to make a tag entry into our database.

} else {

Insert a record to our tagboard database adding the $user name we set, and the $post retrieved from the form.

$query = "INSERT INTO mos_tbd_tags (user, post) VALUES ('$user', '$post')";
$database->setQuery( $query );
$database->query();
}
Did I loose you?  I know this is a lot for a beginning coder, trust me I had to have a lot of help from Peter to get this far. If you have questions, post them on the support forum under the thread for the tag board and I will help you get all this figured out. If you are still lost back up to where you last had a handle on things and read over it again.
Or go ahead and save your form changes by clicking the save button. Again you should be returned to the edit screen with the overview displaying page two. No database has been created and you are a super admin.
 
Now lets fix the trigger on our Make Table button. If you think back we did not set the script for this element in when we defined it. Well the wait is over and now it is time to make it work. Click page two of the form and select the Create Table button from the list by clicking on its Title
.
Click the scripts tab and select Custom from the Action Script section, make sure the click box is selected,
 
and paste this into the text box.
 
function ff_ftb_ctable_action(element, action)
{
    ff_getElementByName('ftb_task').value = 'create_table';
    ff_submitForm();
} // ff_ftb_ctable_action
 
Ill bet you already figured this one out. All we do here is set our hidden element ftb_task to create_table and call the submit process. If you think about our Begin Submit piece, you will remember that if the task is create_table then it fires up the query to make the table and boom, it is done.
Click Save and go ahead and give it a try. If all is well, your query will run, your table will be created and you will be returned to page 1 now because or before form piece detects that the table is there and takes you to page 1.

Ok so lets go ahead and make a post. Type something into the box and click Post.

 
Hmmmm nothing showed up. Ohhhhh wait. I forgot one of the most fantastic parts of FacileForms, not to mention the main piece in our tag board. Lets get that set.
Make sure you have your page 1 selected in your form by clicking on it in the form list.
 
Click the New Icon from the Mambo tool bar, and select input element type Query List. and click continue. Set the elements to these values.
  • Title:              taglist
  • Name:           ftb_taglist
  • CSS all         Leave blank for the moment
  • Ordering       Leave for default     
  • Published      Yes
  • Include log    Yes
  • Pos X            0
  • Pos Y            74
  • Width            100%
  • Rows PP        5
  • Page Nav        none
  • Show Head    no
  • First column    Normal
  • Border            0
  • Spacing           1
  • Padding           1

 
Now Click the Query tab.
Paste this into the query code box
global $database, $exists;

if ($exists) {
    $database->setQuery(
        'select postid,user,post, '.
'concat(post, " by ",user) AS txttag '.
        'from mos_tbd_tags '.
        'order by mos_tbd_tags.postid DESC'
);
    $rows = $database->loadObjectList();
} else
    $rows = array();
 

Again we are back to defining SQL queries and this will require a little work on your part to define the correct query. Refer to my suggestions earlier to get better with queries.
 
Let me explain this one briefly as it uses some commands you might not understand.
 
We set our variables as before.
 global $database, $exists;  // $database is our Mambo global that hooks you up to the database used by Mambo, $exisits is our variable to make sure the table exists.

if ($exists) {

If it does exist we set the query.

    $database->setQuery(

Get postid, user, and post from the table
        'select postid,user,post, '.

Then combine user and post to read "the post text by the poster" and call it txttag.
'concat(post, " by ",user) AS txttag '.

From our table mos_tbd_tags
        'from mos_tbd_tags '.

And sort it in desending order using postid
        'order by mos_tbd_tags.postid DESC'
);

Now click the columns tab.
 
 
Here we tell the element what values to place in our columns. Click the new button  to define a new column. and set the values of our first column like this Change only these items leave the others to default
  • Title:            Check
  • Name:         postid
  • Value:         <?php return $value; ?>

Click Save

Click New to add another column and set these values.

  • Title:           txttag
  • <th> span   1
  • Name:        txttag
  • Attributes    Center Top None
  • Value:        <?php return  htmlspecialchars($value); ?>

Note It is very important to define values in inputs available to public users with the htmlspecialchars function. This prevents people from inserting javascripts into the form that can execute code. Can you say security?
Click the save button

Now save the element by clicking save and BAM your tag suddenly appears. Now go ahead and post a few tags to see how it works.

Now that our little board works, lets use FacileForms CSS styling features to spruce up our tag board. You may have noticed that there were several places to enter style information to forms and elements in the process of doing this tutorial. This is one of the newer features of FacileForms and it deserves attention.

When I was fine tuning the package for www.facileforms.biz, I ran into a problem in that the background of the form was an ugly white box. The problem was that I wanted to put it in a cell that had a background image that needed to show through my form. Enter Peter and his exceptional support of FF. He had already given us lots of ability to style our form. But in Internet Explorer there are issues setting back ground colors to transparent. Peter fixed that before his release of 1.2.5
Now your form can fit over any site graphics and look very nice indeed. See the tagboard on the site to see what I mean.
You can style your form or elements by using existing styles in your template_css. This makes your form blend nicely with other styles on your site. Or, you can do as I did and define custom styles for your form.
In the case of the tag board package that you download I call three styles that you can add to your style sheet and define any way you choose. Here are the three styles and how I applied them to my Tag Board Package.
 
div.moduletableT {
margin: 0px 0px 0px 0px;
width: 100%;
background-color: transparent;
text-align: center;
}
You can assign this to the form by editing the form FF_tagboard and placing the style name in the CSS <div> field. What it does is simply center align the text at 100% and sets the background color to transparent.
You could just as easily set the color to something you choose or even set a background image.

Next I wanted to be able to highlight tags so that they alternated styles and would make it easy to determine where one tag ended and the next began. Much in the same way that mambo uses sectiontableentry1 and sectiontableentry2 to make polls alternate in default styles.

I defined these two styles in my style sheet.

.tagentry1 {
 padding-bottom: 4px;
 background-color: transparent;
 color: black;
}
.tagentry2 {
    background-color: transparent;
    padding-bottom: 4px;
    color: blue;
}

Then assigned them to the tr(data1) and tr(data2) values of the Query List element on the first page of the form ftb_taglist.
This alternates between black and blue text with padding between the posts. To see the effect look at the facile forms site tag board.
 
Well this concludes this tutorial. I have barely scratched the surface of the power and features in the New Version of FacileForms. For instance I did not get into the ability to select rows from the list using the check box feature of the Query List element. That feature allows you to choose records from a list of records returned by your query and act on the chosen records.
 
Also while we touched on the $database, and $my Mambo globals that can be used to access Mambo information we in no way went in to detail. You can learn more about the Global Variables available with Mambo by reading the documentation on MamboForge.net.
 
If you have not tried FacileForms, I encourage you to give it a go, and let us know what you come up with. The support forum is very active and help is easy to get. I will open a thread in the Packages forum to answer any questions about the tag board.
 
Well this is TJay signing off for now, Best of luck with all your projects.

 


Comments

Guest
2006-05-20 03:26:43
i think the following function definition is missing from the tutorial: 
function getPageByName(&$th, $name) 

foreach($th->rows as $row) 
if ($row->name==$name) 
return $row->page; 
return NULL; 
} // getPageByName
 
it should figure below the rest of the custom code under the pieces tab in the Before Form section 
 
thanks Peter and Tim, 
 
Ned 
www.opencontext.be
tjay
2004-12-15 19:17:05
I had Peter look it over and he said there was no need to include that in the piece because it was a built in function in the newer versions. 
Peter can you confirm this? 
If needed I still have the original text that described this function and it could be added back in.
Guest
2004-12-28 22:18:34
Thanks bt i relise that i can't go popst more than 4 lines in the tagboard how do i fix it so that my friends can actually type more than 4 lines of text in the tagboard? 
 
thanks.  
 
Newbie
Guest
2005-01-08 10:43:18
Great! 
but, how can I access another MySQL DATABASE, diferent from mambo and in another Server (let say is another mysql db that is running another application, but i want to insert and make querys with FF)?
Guest
2006-05-20 03:30:05
I had a problem with the sql syntax for the query list element near the end. My system didn't like the single quotes and prefered double ones, and as a result my form just kept on showing up blank. When I changes the query code to: 
global $database, $exists; 
if ($exists) { 
$database->setQuery( 
"select postid,user,post, ". 
"concat(post, ' by ',user) AS txttag ". 
"from mos_tbd_tags ". 
"order by mos_tbd_tags.postid DESC" 
); 
$database->query(); 
$rows = $database->loadObjectList(); 
} else { 
$rows = array();  
}
 
That seemed to fix the problem.
Guest
2005-02-11 11:30:19
Hi, i think that´s all pretty cool but I have a much simpler problem: 
say I have a form with 3 input fields: 
Name FirstName E-Mail 
 
how can I store the data from the form in a predefined table with the same fields? So far, FF stores data in two different tables, mos_facileforms_records and mos_facileforms_subrecords, but that´s not what I need? 
Any ideas or maybe a simple example? 
Thank you very much
Guest
2005-02-11 11:30:33
Hi, i think that´s all pretty cool but I have a much simpler problem: 
say I have a form with 3 input fields: 
Name FirstName E-Mail 
 
how can I store the data from the form in a predefined table with the same fields? So far, FF stores data in two different tables, mos_facileforms_records and mos_facileforms_subrecords, but that´s not what I need? 
Any ideas or maybe a simple example? 
Thank you very much
Guest
2005-03-08 18:52:59
Thank you very much for this tutorial, it really give me confidence in using facile forms 
 
Just a little trick on the part of the tutorial where you invite de user to create a query-list you say  
 
Make sure you have your page 1 selected in your form by clicking on it in the form list.
 
 
Which is fine but the picture show the page 2 button clicked, ok, ok i know that's not really important for guy who read carrefuly the text but it messed me for while. Thanks anyway.
Guest
2005-04-03 08:03:01
Thanks for the great work. I didn't know almost anything about php and sql when I started the tutorial. it was very easy to follow and learn big time in the process.
Guest
2005-05-10 04:47:48
No, pos si esta chidohttp://www.facileforms.biz/content/view/25/47/
Guest
2005-06-01 05:58:21
i loved this tutorial! but i cannot get the data from my form into a predefined table - it still shows up in the manage records section...please help !
Guest
2005-06-01 06:01:13
hi, i've added to all of my form fields that require user input (call me paranoid) but on inspecting the manage records section of Facile Forms, I can see the output rendered as an h3 tag, if I had entered a name and enclosed it in h3 tags in any of the form fields. Why is this happening? 
 
cobnet
2005-07-12 17:49:54
GREAT Tutorial! 
 
We created a form, but how do we access this form outside of admin?
koliver
2006-05-20 03:28:42
I have followed the above example and i am still not able to post a tag. When page one loads i recieve an error on the page. The error says line 17 error object required. It is not able to create a quary. Any suggestions?
koliver
2006-05-20 03:31:13
If I then change the quary code to: 
    $database->setQuery( 
'select postid,user,post, '. 
'concat(post, " by ",user) AS txttag '. 
'from mos_tbd_tags '. 
'order by mos_tbd_tags.postid DESC' 
); 
$rows = $database->loadObjectList();
 
I will not get an error, but nothing will show up on my form. I get a blank page. 
kupcake
2006-01-12 17:11:16
Very nice work on this tutorial. It was very helpful, thanks!
walidn
2006-05-20 03:26:24
I installed joomla using the default configuration and to make this tutorial work with it I had to make some changes.  
first change this line 
if ( $row[0] == "mos_tbd_tags" ) {
 
to  
while( $row = mysql_fetch_row($dataset) ) 

if ( $row[0] == "jos_tbd_tags" ) { 
 
Then  
 
if ($my->usertype == "superadministrator" ) {
 
to  
if ($my->usertype == "Super Administrator" )
walidn
2006-03-06 12:32:02
Change 
"INSERT INTO mos_tbd_tags (user, post) VALUES ('$user', '$post')";
 
to 
"INSERT INTO jos_tbd_tags (user, post) VALUES ('$user', '$post')";
 
regards, 
walid Nehme
amwassil2
2006-03-09 19:45:26
:sigh >>Now save the element by clicking save and BAM your tag suddenly appears. Now go ahead and post a few tags to see how it works.
Ptigrouick
2006-05-20 03:20:37
Hello, 
 
I just want to suggest an enhancement of the walidn's solution to make the php and sql codes work with joomla & mambo without any change. 
 
if ( $row[0] == "mos_tbd_tags" ) {
 
becomes 
if ( $row[0] == $mosConfig_dbprefix."tbd_tags" )
 
 
but don't forget to add $mosConfig_dbprefix in the global declarations at the first line of code 
global $my, $exists, $mosConfig_dbprefix
 
 
further: 
if ($my->usertype == "superadministrator" )
 
becomes 
if ($my->usertype == "superadministrator" || $my->usertype == "Super Administrator" )
 
 
and 
 
"INSERT INTO mos_tbd_tags (user, post) VALUES ('$user', '$post')";
 
becomes 
"INSERT INTO #__tbd_tags (user, post) VALUES ('$user', '$post')";
 
 
Now it should be ok with both Joomla and Mambo. 
Thanks a lot for this good tutorial and for this great joomla & mambo component. Facile forms is really a gem !
walidn
2006-05-20 03:13:43
Change this line 
$query = "INSERT INTO mos_tbd_tags (user, post) VALUES ('$user', '$post')";
 
To this one 
$query = "INSERT INTO #__tbd_tags (user, post) VALUES ('$user', '$post')";
 
The difference is in changing mos to #_ so it will work on joomla
brunoreis
2006-05-19 09:31:52
The first post say about creating a new function, but there is one already in the API as the second post says. But, by the time of this post it has to be tuned up because of a little bug, so take a look at: 
 
http://www.facileforms.biz/forum/index.php/topic,119.0.html 
 
The fix is very simple and can be done by the web interface.
fred2bad
2006-06-28 19:29:50
It seems to work fine with the correction proposed by brunoreis. 
 
Maybe it could be a good idea to update the tutorial with the right code : 
 
  
 
//initialization of ff_functions 
 
$this->execPieceByName('ff_InitLib'); 
 
global $my, $exists;  
$exists = 0;  
$dataset = mysql_query('SHOW TABLES') ;  
$this->page = ff_getPageByName('ftb_intro'); 
 
 
while( $row = mysql_fetch_row($dataset) )  
{  
 
 
if ( $row[0] == $mosConfig_dbprefix."tbd_tags" ){ 
$exists = 1;  
break;  
}  
}  
 
// if it exists got to page 1 
if ( $exists == 1 ) { 
$this->page = ff_getPageByName('ftb_intro'); 
// if it does not exist send the form to the correct page for user type  
} else { 
 
if ($my->usertype == "Super Administrator"|| $my->usertype == "Super Administrator&quot;)
 
$this->page = ff_getPageByName('ftb_ctable'); 
} else { 
$this->page = ff_getPageByName('ftb_ntable'); 

}  
digitalmouse
2006-08-03 09:09:28
fred2bad, your improved snippet is missing the $mosConfig_dbprefix addition to the global declaration line.

Only registered users can write comments.
Please login or register.

 
< Prev   Next >