Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,335
    Thanks
    5
    Thanked 363 Times in 360 Posts

    html forms and passing variables

    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!

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,915
    Thanks
    15
    Thanked 227 Times in 227 Posts
    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.

  • #3
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    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 Code:
    <?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 Code:
    <?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.
    Last edited by djh101; 11-12-2010 at 11:57 PM.
    "Yeah science!"
    Online Science Tools

  • #4
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,335
    Thanks
    5
    Thanked 363 Times in 360 Posts
    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.
    Last edited by teedoff; 11-15-2010 at 06:24 PM.

  • #5
    Regular Coder djh101's Avatar
    Join Date
    May 2009
    Location
    California
    Posts
    616
    Thanks
    48
    Thanked 65 Times in 65 Posts
    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.
    "Yeah science!"
    Online Science Tools

  • #6
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,335
    Thanks
    5
    Thanked 363 Times in 360 Posts
    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.

  • #7
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,915
    Thanks
    15
    Thanked 227 Times in 227 Posts
    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..

  • #8
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,335
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Quote Originally Posted by DrDOS View Post
    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!
    Last edited by teedoff; 11-16-2010 at 02:34 PM.

  • #9
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,915
    Thanks
    15
    Thanked 227 Times in 227 Posts
    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.
    Last edited by DrDOS; 11-16-2010 at 04:47 AM.

  • #10
    New Coder
    Join Date
    Jun 2010
    Location
    usa
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by teedoff View Post
    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

  • #11
    Banned
    Join Date
    Jul 2010
    Posts
    66
    Thanks
    0
    Thanked 1 Time in 1 Post
    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 !

  • #12
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,335
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Quote Originally Posted by DrDOS View Post
    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

  • #13
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,950
    Thanks
    9
    Thanked 724 Times in 718 Posts
    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.

  • #14
    Senior Coder
    Join Date
    Aug 2010
    Location
    High Point, NC
    Posts
    3,335
    Thanks
    5
    Thanked 363 Times in 360 Posts
    Quote Originally Posted by SB65 View Post
    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.

  • #15
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,950
    Thanks
    9
    Thanked 724 Times in 718 Posts
    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....


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •