BBCode [form] tag
The [form] tag allows HTML code to be retrieved from the setup table and displayed on the page. While this is intended for data entry forms, it will work for any HTML. The HTML is processed to replace any variables found embedded in the HTML with the current value of the variables.
By default, the information in the members table is available for the currently logged-in user. These values are retrieved in an array with named elements and are specified like:
$memberInfo[memberName] - to get the member name
$memberInfo[memberEmail] - for their e-mail address
$memberInfo[memberURL] - for their web site address
The elements (memberName, memberEmail, etc.) and the names of columns from the "members" table. You can use the data manager to view the names of all of the columns in your members table. The data manager can also me used to add forms HTML to the setup table.
Note that the memberInfo array is also used whenever a listing of members is created, so any form placed on a page after a [members] tags will not display any variable value information.
Simple forms
For a form that only uses information from the currently logged-in user, just use [form=NameOfForm]. The closing tag is optional. Contentor will look in the setup table for form info where the item name is "NameOfForm".
Creating a form
The action of the forms processor can be controlled by using "hidden" fields as documented on the forms processor page.
A simple form might look something like this:
<form name="mailForm" method="POST" action="/formproc.php">
<table border="0" cellspacing="0" cellpadding="2">
<tr>
<td align="right" nowrap valign="top">Name</td>
<td><input type="text" name="realname" value="$memberInfo[memberName]" />
</td>
</tr>
<tr>
<td align="right" nowrap valign="top">E-mail:</td>
<td> <input type="text" name="email" value="$memberInfo[memberEmail]" /> </td>
</tr>
<tr>
<td align="right" nowrap valign="top">Comments:</td>
<td> <textarea name="comments" cols="60" rows="5" wrap="VIRTUAL"></textarea>
</td>
</tr>
<tr>
<td align="right" nowrap>
<input type="hidden" name="to" value="support*contentor.net" />
<input type="hidden" name="options" value="5" />
</td>
<td> <input type="submit" name="Submit" value="Submit"> </td>
</tr>
</table>
</form>
Radio buttons, Checkboxes, Option selectors
Since the HTML form input tag for these input types does not lend themselves to easy "fill-in" by the saved data, some mechnism is needed to indicate which selection was previously stored in the database. To facilitate this, the "comment" field of the setup table is used to store executable PHP code. If the "comment" field starts with a "$" symbol, it is considered to conatin PHP code which will be executed just after the data is retrieved from the database and just before the variables are substituted into the form HTML code. This allows a variable or array to be generated that will set the proper attributes in the input tags.
For example, for a radio button, set the "info" field to hold the modified HTML as:
none: <input type="radio" name="member_howmany" value="0"$checked[0] />
one: <input type="radio" name="member_howmany" value="1"$checked[1] />
two: <input type="radio" name="member_howmany" value="2"$checked[2] />
three:<input type="radio" name="member_howmany" value="3"$checked[3] />
The "checked" array is created and filled with the following PHP code placed in the "comment" field:
$checked = array();
$checked[$memberInfo[member_howmany]] = ' checked="checked"';
This would set the correct element in the array to hold the "checked" attribute to match the correct input line. A similar method can be used to designate the selected element in an option input tag. Make certain the the first "$" is the very first character in the field.
Tip: if you need to execute other PHP from the "comment" field and the "$" would not be the first character of that code, place a "dummy" assignment line first, such as "$temp=$temp;" and then place the rest of the code.
Advanced features
While the [form] tag is ideal for filling out forms, it can also be used for displaying information from the database. Data can be displayed inside any HTML layout.
[form=FormName]SELECT * FROM `table` WHERE `field`='value'[/form] - runs the specified query and makes that information available in an array named "$data".
For example:
The entry in the setup table where `item` = 'ShowAddressPhone' might contain:
<tr>
<td>$data[name]</td>
<td>$data[address]</td>
<td>$data[phone]</td>
</tr>
This would then be used in a section such as:
People from Dahlonega:
<table border="0">
[form=ShowAddressPhone]SELECT * FROM `addresses` WHERE `city`='Dahlonega'[/form]
</table>
You would need to start and end the table, as the form in the database only has the HTML for individual rows that are repeated for each returned name.
Notes
The routine will include a copy of the output for every match specified by the query.
If a column called "Form" exists in the queried table, the contents of that column will be used as the form name instead of "FormName" as shown in the example. This would allow for a custom output format for each row of data.
All error messages are suppresed. Since this may make troubleshooting difficult, a different MySQL tool (i.e. phpMyAdmin, MySQL-Front, etc.) should be used to develop and debug queries.
Also note that this tag allows listing of members' entries regardless of the "private" setting. Any listings of members should be done with great care or with the [members] tag in order to honor the privacy settings.