...

View Full Version : html forms and passing variables



teedoff
11-12-2010, 10:45 PM
Ok I have several issues I'm trying to wrap my head around. First, I'm trying to figure out the best way to create a "template" of some sorts for building new pages.

One problem is: the site is a completely static html site with no server-side script needed or available presently.

Second, I have created a template in Dreamweaver, but the problem is that the person that will be using this template doesn't have dreamweaver. We might can work around that, since I have several versions of adobe that could be used, but obviously loading the page in our local browser negates the template's editable regions.

Another solution would be a form similar to a form used for data insertion into databases, however, I'm not altogether sure this is possible with just html. Surely I can do it using coldfusion, maybe even php, but again not sure these would be an option.

That poses two more problems either way. One being the shopping cart form. I would love to be able to edit the form values themselves, but after trying to a while now, it seems not possible. SInce the shopping cart is one every product page, it should be an editable region in the template, with the only things changing are the input values themselves. Again, not sure this is possible with html.

Last issue is the fact that I need to be able to edit elements in the head section. Page title and especially meta-data such as keywords and descriptions.

Would love any feedback and tips or suggestions for this issue. Thanks!

DrDOS
11-12-2010, 11:02 PM
I seriously think you should get some server side language support. Without it you're pretty much reduced to javascript, which will be buggy, slow and insecure by comparison. On the other hand, with PHP for example you have some 700 built in functions, plus whatever you can make up, and many will handle simple text files and database as well, making it much simpler to make entries and edit them.

djh101
11-13-2010, 12:41 AM
If you really want, you can use server side scripting for the template and still output the pages into HTML. Otherwise you're, like DrDos said, stuck with Javascript all by itself. You could use keep your template in a txt file and use fread to pull the code up to the editing page. Then you could add in some data with a few forms (at minimum, title and content), and save it to a new html file.

thisPage.php:


<?php
$title = $_POST['title'];
$content = $_POST['content'];

include("template.php");

$newFile = $title.".html";
$fileHandle = fopen($newFile, 'w');
frite($fileHandle, $content);
fclose($fileHandle);
?>
<html>
<head>...</head>
<body>...
<form action="template.php" method="post">
<fieldset>
<input type="text" name="title" />
<textarea name="content" />
<input type="submit" name="submit" value="Submit" />
</fieldset>
</form>
</body>
</html>


template.php

<?php
$content = "
<html>
<head>
<link href='styles.css' type='text/css' rel='stylesheet' />
<title>".$title." - My Website</title>
</head>
<body>
<div id='navigation'>
<ul>
<li><a href='somePage.html'>Some Page</a></li>
<li><a href='someOtherPage.html'>Some Other Page</a></li>
</ul>
</div>
<div id='content'>
".$content."
</div>
</body>
</html>"
?>

EDIT: Actually, what would be easier would be to have template as an included PHP file, that way you could have everything already variableized and ready to go. Or, if you wanted to load everything from template.txt into a textbox, you could edit the HTML directly in the page.

teedoff
11-15-2010, 07:21 PM
Ok I built a simple form using php and a results page to echo all the data used to build a new page. I may be going about this wrong, but I am very new to php and really didnt understand your reply(Djh101).

The problem I see now is that I would love to able to create new pages with .html as the file ext. The results page, having php scripting on it, is .php.

Another issue would be the file name itself. Instead of the form action going to a generic formResults.php page, there must be some way of replacing that with a dynamically generated .html file name.

I hope I made sense..lol Im not sure it makes sense to me yet...lol

At this point, this may actually need to be moved to the php forum.

djh101
11-15-2010, 11:58 PM
First of all, sorry, <form action="template.php" method="post"> should be <form action="thisPage.php" method="post">

You can replace the url I used with anything you want- whatever url you use, though, is where the form data will be sent. If you want to retrieve it with PHP, though, the page has to be .php (what's wrong with .php, though?). What's happening in the script is only the template creation page is a .php file. What this does is it takes the information you entered in the title input box and creates a new file with it (and a .html extension)(once you get that down, I should probably show you how to replace space with _s), so your actual pages will still be in HTML. When the form is submitted:
1. The data from the 'title' field of your form is given to the $title variable and 'content' to $content.
2. template.php is included in the page (meaning all the data inside that file is inserted into this one). $title and $content are inserted into the $content variable from template.php where they are called.
3. $newFile becomes the name of your new file. So, let's say you submitted File1 into the file field, $newFile would become File1.html.
4. $fileHandle attempts to figuratively open File1.html so that it can be written to. If File1.html does not exist, it is created (it is possible to check if it already exists beforehand to avoid overwriting).
5. $content (remember that this variable now contains the information from template.php) is written to the file with frite (this should actually be fwrite, sorry).
6. The file handle is closed and the PHP script is ended. You should now have a new file called File.html with all the appropriate information.

If you've never used a server side language or programming language before, this might be a little confusing, so keep asking questions and I'll try to answer them. Again, only your template creator is in PHP, the outputted files will be in pure html.

teedoff
11-16-2010, 12:28 AM
Hi djh. Im new to php...I have been a cf developer, but this is quite different.

OK well I think I kinda did my own thing..lol because I didnt quite understand what you were suggesting I did.

I created two files. formPage.php and formPageResults.php.
Once the user types data in the form fields, then the form action posts and echoes all the form values to their respective "places" in the results page.

But, while nothing I guess is fundamentally wrong with keeping the page .php, I would rather keep with the rest of the thousands of pages and use the standad .html file extension.

I read and pretty much understand the str_replace() function, but didnt know if it would work for a file name extension. I also read soewhere that I could edit the htaccess folder to allow html files to run php script. But not sure that I want to be editing a folder on the remote, especially since this will be a local application that will save the new product pages to our HDD and then get uploaded to the remote server each night.

DrDOS
11-16-2010, 04:47 AM
Here's how you save a php page as an html page. At least, this works on Firefox ( thank goodness for Firefox ). Make a page that has a link to formPageResults.php. After you have written the code to formPageResults.php, access the page with the link on your localhost, right click on the link and save the link as whatevernameyouwant.html. It will be pure html without any php code on it. Do not use the save as complete webpage as that will mess up the pathnames..

teedoff
11-16-2010, 04:50 AM
Here's how you save a php page as an html page. At least, this works on Firefox ( thank goodness for Firefox ). Make a page that has a link to formPageResults.php. After you have written the code to formPageResults.php, access the page with the link on your localhost, right click on the link and save the link as whatevernameyouwant.html. It will be pure html without any php code on it. Do not use the save as complete webpage as that will mess up the pathnames..

hmm that sounds like a cool trick! lol...I'll try it first thing tomorrow at work. Thanks!

DrDOS
11-16-2010, 05:22 AM
More ideas. In addition to formPage.php and formPageResults.php, for each text field in your form have a sub page, could be sub1.php, sub2.php, etc. These will just be blank plain text documents with no code ( no php tags either ) and are temp files that get overwritten each time you make a new page. their contents will just be included in formPageResults.php. formPage.php will format any text, tables, links, etc, and use fopen, fwrite and fclose to write to the sub pages. After they are written they will have whatever text, html, script, etc. that you want included in the new html page. This will actually be simpler and safer than trying to do everything with the two pages alone.

PS: I see that djh101's way is using variables as 'temp files' and just echoing them. Have to check that method out myself.

mahesh2010
11-16-2010, 09:48 AM
Ok I have several issues I'm trying to wrap my head around. First, I'm trying to figure out the best way to create a "template" of some sorts for building new pages.

One problem is: the site is a completely static html site with no server-side script needed or available presently.

Second, I have created a template in Dreamweaver, but the problem is that the person that will be using this template doesn't have dreamweaver. We might can work around that, since I have several versions of adobe that could be used, but obviously loading the page in our local browser negates the template's editable regions.

Another solution would be a form similar to a form used for data insertion into databases, however, I'm not altogether sure this is possible with just html. Surely I can do it using coldfusion, maybe even php, but again not sure these would be an option.

That poses two more problems either way. One being the shopping cart form. I would love to be able to edit the form values themselves, but after trying to a while now, it seems not possible. SInce the shopping cart is one every product page, it should be an editable region in the template, with the only things changing are the input values themselves. Again, not sure this is possible with html.

Last issue is the fact that I need to be able to edit elements in the head section. Page title and especially meta-data such as keywords and descriptions.

Would love any feedback and tips or suggestions for this issue. Thanks!

Hi,
When you create any template check it in multi browser
second one is best way for designing a template is manual method
without any server side script we cannot handle shopping cart or pass values from forms its better to use php as server side scripts any query let me know

santhoshj400
11-16-2010, 10:00 AM
Hi,
I recommend you to prefer any server side script without script we cannot pass values from one form to another and it is better to use java script for uploading pourpose and php that would be fine !

teedoff
11-16-2010, 03:29 PM
More ideas. In addition to formPage.php and formPageResults.php, for each text field in your form have a sub page, could be sub1.php, sub2.php, etc. These will just be blank plain text documents with no code ( no php tags either ) and are temp files that get overwritten each time you make a new page. their contents will just be included in formPageResults.php. formPage.php will format any text, tables, links, etc, and use fopen, fwrite and fclose to write to the sub pages. After they are written they will have whatever text, html, script, etc. that you want included in the new html page. This will actually be simpler and safer than trying to do everything with the two pages alone.

PS: I see that djh101's way is using variables as 'temp files' and just echoing them. Have to check that method out myself.

Hey DrDos, thanks for the info! I understand what you mean by creating these subpages. I still dont understand how that will result in a final page saved in html instead of php. Again, I'm trying to make this as automated and seamless as possible in order to allow someone to use in an office who has no coding experience at all. I think what im trying to do is have all data entered for the new page, then with a single click of a submit button, generate the new html document. Maybe this is not possible in one single step on her end.

Sorry again for my noobness in php...lol

SB65
11-16-2010, 04:00 PM
I'm a bit confused reading this post. In the original post you say there's no server side scripting available - which I took to mean that php is unavailable. Surely, if php is unavailable, then you can't use php for anything.

Or are you saying that you can use php but just want to disguise its use, although I don't understand why, and call it from pages with html extensions?

Or maybe I've completely misunderstood....sorry if this isn't helpful.

teedoff
11-16-2010, 04:11 PM
I'm a bit confused reading this post. In the original post you say there's no server side scripting available - which I took to mean that php is unavailable. Surely, if php is unavailable, then you can't use php for anything.

Or are you saying that you can use php but just want to disguise its use, although I don't understand why, and call it from pages with html extensions?

Or maybe I've completely misunderstood....sorry if this isn't helpful.

Yes sorry for the confusion. I should have said, with my limited knowledge of php, I would love if there were other options...lol

Yes I can use php, but my employer has expressed that he still wants new pages created and saved in an html document.

I have a form and the results page completed. The problem is each time the form is filled out with data to create a new page, the results page is 1) saved as a php file, and 2) has the name formResultsPage.php.

Once the data is entered into the form, I want to somehow be able to change the results page to an html page.

I hope that clears it up for you, and again sorry for the confusion.

SB65
11-16-2010, 04:24 PM
No need at all for apologies.


my employer has expressed that he still wants new pages created and saved in an html document.

I realise it's easy for me to sit here and say why, but...why? I'd imagine most people don't notice what sort of page they're looking at and care even less.

It just seems like it's a lot of effort (and worse, over-complicating things) just to deliver something that won't make any difference to the user.

However, maybe it's just one of those JFDI moments....:D

DrDOS
11-16-2010, 04:33 PM
Not to worry, I'm just learning PHP myself, but I've been thinking about ways of making it easy and relatively foolproof for people to make their own web pages online, for quite a while.

Did you try the 'right click and save target' method of making a php page into an html page yet. It might be simple enough, and it certainly works. Just save those pages to a folder and upload the contents of the folder to the server.

teedoff
11-16-2010, 04:33 PM
No need at all for apologies.



I realise it's easy for me to sit here and say why, but...why? I'd imagine most people don't notice what sort of page they're looking at and care even less.

It just seems like it's a lot of effort (and worse, over-complicating things) just to deliver something that won't make any difference to the user.

However, maybe it's just one of those JFDI moments....:D

lol my sentiments exactly. I just spoke with him this morning specifically about the .php extension questions. He owns this business and has built it AND his static site(which contains thousands of pages) himself. Not the best way to do it, but it works and it works well for him, so who am I to argue...lol

Again, I think he thinks that anything other than .html will have an adverse effect on his google rankings, which presently are excellent with the static, ugly text heavy pages he has.

He has no problem with php elements being on his site, as I incorporated a search function written in php, which isnt working remotely for some reason...lol but again he isnt keen on his pages being "somepage.php"

Yes this does create headaches and extra work/steps for most everything I do here. Believe me I know. Still working on the database he didnt have at all...and only about 1/4 the way done.

So I guess my onlu option is somehow to figure out how to rename the results page with an html extension. Now obviously I could create the php page, view source and then copy and paste this in another new html page, but this will mainly be done by a girl here in the office, so I want to make it as simple as possible.

btw..not sure what JFDI means...hahaha

SB65
11-16-2010, 04:43 PM
Ok, fair enough. What about using .htaccess to change your file extensions? A brief google brings up lots of stuff including this one (http://www.besthostratings.com/articles/php-in-html-files.html).

Just my thoughts anyway. I'll shut up now.

JFDI: "Just f..... do it". I forget what the f stands for. Used by senior managers, often in exasperated tones, when they pull rank despite strong arguments against them.

teedoff
11-16-2010, 05:12 PM
Did you try the 'right click and save target' method of making a php page into an html page yet. It might be simple enough, and it certainly works. Just save those pages to a folder and upload the contents of the folder to the server

No I havent tried that yet. I've been somewhat busy with finding a new hosting company. I will do that today though. Sounds simple enough, but remember this process will be used by someone who knows nothing about file saving or folder uploading. Which for that matter I could do that part.


Ok, fair enough. What about using .htaccess to change your file extensions? A brief google brings up lots of stuff including this one.

Just my thoughts anyway. I'll shut up now.

JFDI: "Just f..... do it". I forget what the f stands for. Used by senior managers, often in exasperated tones, when they pull rank despite strong arguments against them.

Yes I have looked into the htaccess editing. The question is, if all this is done locally, which file/folder would I edit on the local server?

teedoff
11-16-2010, 05:50 PM
Is there a file I can edit locally to run php script from html pages??

DrDOS
11-16-2010, 06:00 PM
Is there a file I can edit locally to run php script from html pages??Is this local machine separate from the server. It would have to be a php enabled server, and the parser would read all the html pages as well as php pages, which might slow things down a lot.

teedoff
11-16-2010, 06:02 PM
Is this local machine separate from the server. It would have to be a php enabled server, and the parser would read all the html pages as well as php pages, which might slow things down a lot.

We dont host our own sites if thats whay you mean. I have WAMP installed on my machine for php and the fact that I have been creating a database in MySQL since day one.

I guess ideally would be to install WAMP on her machine as well.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum