Forum Moderators: coopster
what I want to do is to write some code that will allow users on my site to enter their information and then automatically generate a page on my site.
specifically, my site is a registry for volkswagen westfalia campers <snip>, I have a couple dozen vehicles registered on my site, for which I wrote all of the pages myself. I am expanding it and I would like to be able to have most or all of the pages written automatically from user input on a registry page where I get the information with forms. I am somewhat knowlegeable in the programming world. I have written html, java and C++, so I know what programing is.
what I need to do is to have the page that accepts the user input generate a page from a template that I will write. I need to do this with text and hopefully photos. I wouldn't mind maipulating the photos manually to get the best quality, but I don't want to be writing the same general text pages over and over.
does anyone know exacly what calls I need to use to do this and any pitfalls associated with doing this.
thanks in advance.
--lind
<snip>
[edited by: ergophobe at 2:14 pm (utc) on Aug. 29, 2004]
[edit reason] removed URL and email [/edit]
Welcome on Webmaster World
I will do an OOP with template pages
First you need to get from the user a few info such as name, username etc...
Pass the info to a script that will among other actions pass the info to a DB
Then
Open a Dir (your page template dir) copy a page to a new dir
Open the new file and pass the new created ID to the new file
Remember that since you are in a multiple users mode you need to specifically identify each file
Then
Rename that file for ex: car_1 and auto generate and URL for that page
That can be made out of a concatenation again for ex car_id_001.php
You will also need to dynamically generate a nav bar to call those new URLs
Now for the fun part
This will be the template sample coding
<?php # car###.php
//error_reporting (E_ALL);
$id= ;// this where you will pass the ID
// This is the CAR page that uses the HtmlTemplate_car class.
require_once ("include_fns_group.php"); // Include the configuration file.
require_once ("../classes/HtmlTemplate_car.class"); // Include the class.
$page = new HtmlTemplate_car ("../templates/main_template_car.inc.php"); // Create an instance.
$page->SetParameter("PAGE_TITLE", "Member Home Page");
$content_21 .= '';
include "includes/late_nav_svces.inc.php";
$page->SetParameter("LATE_NAV_SVCES", $content_21);
##############
This would be your main_template_car.inc.php
<title><!--{PAGE_TITLE}--></title>
<body topmargin="0" marginheight="0" marginwidth="0" bgcolor="#ffffcc">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" valign="middle">
<tr>
<td width="100%" align="center" valign="top" colspan="3">
<!-- first table 3 rows (1 is a nested table) -->
<table width="100%" border="0" align="center" cellspacing="0" cellpadding="0" valign="top" bgcolor="#ffcc66">
<tr>
<td width="100%" height="40" align="center" valign="middle" colspan="3" bgcolor="#800000">
<div class=top_name>
<font color="#ffffff">
<!--{BUSINESS_NAME}-->
</font>
</div></td></tr>
<!-- // lateral_nav -->
<tr>
<td width="100%" align="left" valign="top" colspan="3">
<table align="top" width="100%">
<td width="33%" align="top" valign="left">
<div class="intro1">
Products & Services: <!--{LATE_NAV_SVCES}-->
#######
Finally the class
class HtmlTemplate_car {
// Set the attributes.
var $template;
var $html;
var $parameters = array();
function HtmlTemplate_car ($template) {
$this->template = $template;
$this->html = implode ("", (file($this->template))); // Read the template into an array, then create a string.
}
function SetParameter ($variable, $value) { // This function sets the particular values.
$this->parameters[$variable] = $value;
}
function CreatePage () { // Your most important function!
foreach ($this->parameters as $key => $value) { // Loop through the parameters and set the var to values.
$template_name = '<!--{' . $key . '}-->';
$this->html = str_replace ($template_name, $value, $this->html);
}
echo $this->html;
}
Last a word on PHP5
This class will not work in PHP5
"Var" key word is deprecated and will need to be replaced by
"private" or "protected"
for ex:
var $template
will become private “$template” or “protected $template”
read here or look at the php manual
Further this is only the very basics
in addition you need an authentication system
and you own CMS to allow for edit/delete of users' own pages
as well as dealing with images
but this will be a LONG part 2 :)
Regards
Henry