d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Write To Html File Using Php / Js > Tipping With Fg
Add Reply New Topic New Poll
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Aug 15 2013 08:17am
Hello kind and knowledgeable web programmers,

I am currently working on a project for school.
In order to complete this project to standards, I must design a webpage with several input forms. Each input form much then physically write text/HTML to a HTML template to fill in certain predefined elements.

I am in need of a recommendation of what language/technology I should use to complete this task. I imagine PHP would be the best choice, though I believe this could also be accomplished fairly easily using JavaScript?
Also, it would be highly appreciated if one could kindly write a very short example or just point me towards what functions I should use / what W3School pages I should look at.

Thank y'all!

- Grievance
Member
Posts: 2,757
Joined: Nov 26 2007
Gold: 1,214.81
Aug 15 2013 09:23am
Are you trying to do something like this?

Code
<!DOCTYPE html>
<html>
<head>
<script>
function displayInfo()
{
document.getElementById("fname").innerHTML="First Name: " + document.forms["myForm"]["fname"].value;
document.getElementById("lname").innerHTML="Last Name: " + document.forms["myForm"]["lname"].value;
}
</script>
</head>
<body>
<form name="myForm" onsubmit="displayInfo()" method="post">
<p>First Name <input type="text" name="fname"></p>
<p>Last Name <input type="text" name="lname"></p>
</form>
<p id="fname"></p>
<p id="lname"></p>

<button type="button" onclick="displayInfo()">Submit</button>

</body>
</html>
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Aug 15 2013 09:55am
Quote (labatymo @ Aug 15 2013 09:23am)
Are you trying to do something like this?]


I believe your code is getting pretty close, but isn't quite what I'm looking for.
Let me go ahead and give a few more details.

I have created an HTML template with internal CSS, we'll call it template.html.

I want to collect data using forms on a separate webpage, getdata.html
Afterwards, I want to amend certain elements in template.html with the data collected from getdata.html
Finally, I want to save the amended template.html using a new file name such as amendedtemplate.html

Essentially, with very little technical knowledge, the end-user should be able to fill out a few forms such as..

Code
<p>New Webpage Name <input type="text" name="pagename"></p>
<p>Img URL 1 <input type="text" name="imageone"></p>
<p>Img URL 2 <input type="text" name="imagetwo"></p>


After all is said and done and the information gets handed to as many pages as necessary the final product will be a new webpage that looks exactly like template.html except it will have a new name and different images.

Hopefully this makes sense.
I know it's not the simplest of requests, hence why I'm looking for some advice.
That being said, thank you labatymo for your response/help.

This post was edited by grievance on Aug 15 2013 09:56am
Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Aug 15 2013 10:40am
I believe I have figured out my solution. It would seem as if I was over thinking it a "tad" bit :P
Though, any suggestions are still more than welcomed.
Member
Posts: 2,612
Joined: Nov 8 2005
Gold: 90.00
Aug 15 2013 10:44am
Since this doesn't use a database, as you would normally in these cases, i'm guessing this is an exercise for file manipulation...PHP is a definite the choice for this.

The right way to go about it, would be to create one single template file, and have it pull from a single text file (acting as a database) with all the submitted data. But this project wants the application to write a new html file for each submission, which isn't so elegant, but we'll play along.

The functions you want to practice in this case are all here on this page:

http://davidwalsh.name/basic-php-file-handling-create-open-read-write-append-close-delete

You can do this with a single php file for everything...submitting the data, writing the html, and pulling up all written files by reading them in the directory and listing them in a dropdown. Go from there and let us know if you stuck!


Member
Posts: 2,217
Joined: Sep 10 2007
Gold: 35.88
Aug 15 2013 11:06am
Quote (notFrench @ Aug 15 2013 10:44am)
Since this doesn't use a database, as you would normally in these cases, i'm guessing this is an exercise for file manipulation...PHP is a definite the choice for this.

The right way to go about it, would be to create one single template file, and have it pull from a single text file (acting as a database) with all the submitted data.  But this project wants the application to write a new html file for each submission, which isn't so elegant, but we'll play along.

The functions you want to practice in this case are all here on this page:

http://davidwalsh.name/basic-php-file-handling-create-open-read-write-append-close-delete

You can do this with a single php file for everything...submitting the data, writing the html, and pulling up all written files by reading them in the directory and listing them in a dropdown.  Go from there and let us know if you stuck!


<3 ! Kudo!
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll