Hello Brothers and sisters,
I'v got a problem,may it look like simple,but it shakes me off,let me state this.
1.I need to enter some details such as name,address and a photo in an html form.
2.On clicking submit button,I should get an html page with the contents I'v entered.
3.The html page generated should be saved in a predefined directory automatically.
4.The above 3 steps can be repeated several times,but the html pages should have
same alignments and positioning.
Can anyone give me a solution???????????
Rajeesh.N.Santhu

The easiest way would be to use php.
It would also work with Javascript, but much more complicated

what do you want to use?

Hello Agarsia,
Thank you for your helping hand.
I am doing my project in HTML+JAVASCRIPT and its possible to include php,
although,I would like to know whether its possible using servlet or javascript.
Rajeesh.N.Santhu

I'm not good in servlets and i dont know how to save files in javascript... i would use PHP, just use a html file with a form like this:

...
<form method="post" action="output.php">
 Name: <input type="text" name="name" /><br />
 Adress: <input type="text" name="adress" /><br />
 Photo: <input type="file" name="photo" /><br />
<input type="submit" value="Submit" name="submit" />
</form>
...

now create the output.php like this:

<?php
if(isset($_POST['submit'])) {
 $name = $_POST['name'];
 $adress = $_POST['ddress'];
 $photo = $_POST['photo'];

 //Read the file which includes the html page in which the data should be filed and should be returned
 $file = file_get_contents("input.html);

 $file = str_replace('%name%', $file);
 $file = str_replace('%adress%', $file);
 $file = str_replace('%photo%', '<img src='.$file.' alt="" />'); //Maybe validate and upload the Photo

 file_put_contents($name.".html",$file); //Creates a file named $name.html which will output the finished document
}
?>

and now the input.html: change it like you want

...
<h1>My name is %name%</h1>
<p>I live in %address%</p>
%photo% <br/> Thats me :)
...

the tags in the input.html with %...% will replaced by output.php with the data writen in the first html file.
the input.html with the data included will be saved in the output.php.

Hello Agarsia,,,
You have done it,,,thanx lot...let me try it,,,I'll check it and inform you,
Rajeesh.N.Santhu

php,works.....can anyone help me with javascript????????

hm for the javascript thing i only know one solution, which will only work with internet explorer, this is an ActiveX-Object.. but i dont know that Chrome or Firefox or Opera support any solution, because its very unsecure and hackable

You can do it via Servlet in the 'doGet()' or 'doPost()' method depending on how you implement your Servlet. If you implements 'doPost()' to call 'doGet()' (which is usually the way it is), then you just need to do it in 'doGet()' by obtaining the value of the parameter from view, and then write it out.

To do it in JavaScript, you won't pass any parameter to the server. One problem here, you are not allowed to access local storage if the browser is not IE because of security issue. IE has ActiveXObject which allows local storage access (dangerous though). One way to do it with JavaScript without saving in a file and not use ActiveXObject (but work for all browsers) is to use Cookies.

Hey, I am not able to run your code. It is not giving the desired output.After filling the form it is redirecting to output.php and now giving any result. It is not creating input.html. Can you please help me?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.