Forum Moderators: mack

Message Too Old, No Replies

Creating new static pages automatically

Having a submit form on website - with data entered creating new page

         

Onders

9:59 pm on Dec 20, 2004 (gmt 0)

10+ Year Member



Wondering if somebody out there can give me a bit of guidance.
Am thinking of implementing something on my website whereby people can fill in an online form, submit it, which creates a new static page. This static page will already have certain info on it, including the new info. It will also have to generate a link from lets say the homepage to this newly created static page.

Sorry, probably haven't explained this very well - does anyone have any ideas on how to do this or if it's possible. Am trying to get round using dynamic pages. No search function is necessary..
Thanks

CanadianChris

4:01 am on Dec 21, 2004 (gmt 0)

10+ Year Member



Something like that is easy to create provided your website supports either PHP or Perl programming (although I bet somebody out there could do it in javascript).

The coding would only take like 15-20 lines in PHP. And you should be able to easily find a script out there that is free to use.

MichaelBluejay

12:36 pm on Dec 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you want the page to be *saved* to the server then you can't do it with JavaScript, since JavaScript dosn't read and write files for security reasons. If you just need the user to see the page on the screen, once, and you don't need anyone else to ever see it, then JavaScript will work fine.

If you do need to save the page to the server, then be careful since people may use it to create pages of backlinks to their own sites, or promote their own products, etc.

If you're saving pages to the server then I agree that PHP or Perl would be the best way to go.

claus

1:05 pm on Dec 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> although I bet somebody out there could do it in javascript

Yep, with JPspan [jpspan.sourceforge.net] or a XMLHttpRequest thingy [xulplanet.com] you could do it, but that would only be a JS "interface" to some other serverside thingy (former: php - latter: Perl, PHP, ASP, .NET, Java, Python, whatever, (example) [webmasterworld.com]), so you might as well do it fully serverside.

Another reason to do it serverside is that you will probably want the browser to go to that new page as soon as it's generated, so there's really no need for a JavaScript "middleman".

claus

11:25 am on Dec 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As requested by sticky, i'll expand a bit on "how to do it". I'll leave out javascript as well as databases, to make it as simple as possible.

Doing this serverside (ie. with perl, php, asp, .net / whatever) means more than just writing a few lines of code unless you know exactly what kind of input and output you want.

One way to do it (without using a database) is:



PART ONE: CREATING THE PAGE

1) Set up a template page with the information that should always be on the page.
1a) Add "placeholder tags" for the form-submitted information you want on the page (unique strings that you make up yourself)

2) Setup a form page with input fields for the extra information you want on the new page

3) Let the form post to a script (4)

4) Create a script, that:
4a) Accepts and validates data sent from form in (2)
4b) Retrieves the template page from (1) and parses it, inserting the values from the form in stead of your placeholder tags
4c) Saves the updated template page with some name in some folder
4d) Updates some file by inserting the name and URL of the new page
4e) Sends a "Location: somedomain.tld/pagename.htm" header to the browser, making it switch to the new page.

PART TWO: CREATING LINKS TO THE PAGE
On the pages you want to link to the new page:

1) make sure they are server parsed, ie. ".shtml", ".asp", ".php", ".pl", ".jsp", or whatever technology you wish to use

2) Make the page call a script that checks the file mentioned in part one (4d)

3) Make that script insert the link to the new page before the "page that links to" get displayed to the visitor.

PART TWO: ALTERNATIVE VERSION
Extend the script in part one (4) so that it will retrieve and parse the files/pages you want to link to the new page. Make the script insert links on those pages and save them. That way, they can be static pages as well.

Make this part happen after part (4e), ie. after your visitors get the new page. They should not have to wait for this.


There are always other ways to do it, but the steps above should be sufficient to get some kind of system operational without using databases. (yes, i know that technically, the file mentioned in (4d) is a "flat file database" - still, this is without a dedicated database application like "somethingSQL"