PHP Templating

I’ve always wanted to create a CMS system using PHP. I currently have an opportunity through my work to develop a custom form webapp for one of our clients, which I’ve been working on non-stop for the past day or so.

I’ve got no idea how anyone else does templating, but I’ve devised my own little method to replace BBCode style tags embedded within HTML with little bits of code here and there. It really is nasty, but it does the job. At the moment, all it’s being used for is to create a form, which is dynamically updatable by our client so they can add new fields and new forms as required.

"; } elseif (preg_match("/\[label:(\w+)\]/",$replaceThis,$labelField)) { $labelField = $labelField[1]; $replacement = ""; } else { switch($fields[$fieldName]['type']): case 'text': $replacement = " "; break; case 'textarea': $replacement = ""; break; default: $replacement = " "; endswitch; } $templateHTML = preg_replace('/\['.$fieldName.'\]/',$replacement,$templateHTML); } echo $templateHTML; } else { ?> No form selected!

The template data is actually stored in the database as follows:

[label:clientName][clientName]
[label:zone][zone]
[label:cssc][cssc]
[label:cso][cso]
[label:date][date]
[label:behaviours][behaviours]
[label:stability][stability]
[label:selfcareskills][selfcareskills]
[label:academics][academics]
[label:intellect][intellect]
[label:familycontact][familycontact]
[label:substances][substances]
[label:health][health]
[submit]
0 0 votes
Article Rating

Posted

in

, , ,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0
Would love your thoughts, please comment.x
()
x