• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

Writing to a file

How do I take Text info from an html form and write it to a file on the web server?
Here is my html form:

<FORM NAME=mainform action= method="post" onsubmit="return Validate1()">

Please enter you name:
     <INPUT id=text1 name=name1><br>
What is your phone number:
     <INPUT id=text2 name=phone1><br>
what is your email address:
     <INPUT id=text3 name=mail1><br>

<INPUT id=submit1 type=submit value=Submit name=submit1>
<INPUT id=reset1 type=reset value=Clear name=reset1></P>
</FORM>
0
hirschhouse
Asked:
hirschhouse
  • 9
  • 7
  • 5
  • +4
1 Solution
 
dorwardCommented:
It depends. First you need to target the form at a URL which houses some form of server side program. What do you have on the server?

PHP? ASP? Python? Perl? C? JSP? Ruby?
0
 
a.marshCommented:
That's right - let us know what server-side scripting you have available and we can help you further.

:o)

Ant
0
 
hirschhouseAuthor Commented:
ASP at home, that is where i'm developing the form. However, the website will live at hostsave.com when im done. They say they support Fontpage extensions cgi, Perl & PHP. I just emailed hostsave asking if they can handle asp.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
dorwardCommented:
The other question is do you really want to use a file, it could be better to use a database instead.
0
 
a.marshCommented:
I personally work with PHP - you can set it up at home for free.

Go to:

http://www.php.net/

for more info.

:o)

Ant
0
 
hirschhouseAuthor Commented:
A file or DB would be ok. I don't expect to much traffic. This PHP stuff looks neat alot of stuff though, can you give me more direction?
0
 
dorwardCommented:
There are some good beginner tutorials for PHP at http://www.devshed.com/ including on that goes through setting up a server that supports it (although I think that might be targetted at Linux rather then Windows - although PHP will run under Windows as well).

I suggest finding out what databases are available on your provider, MySQL and Postgresql are probably the most common (and both are free).
0
 
daluuCommented:
PHP scripting is a good choice to use. I'm just learning it and I like it. But if you want to setup the form quick, FrontPage w/ ASP and perhaps a database can do it in an instant. The FrontPage program will handle all the scripting and the database creation if you will use Access or you can specify a database to connect to. The following is an article on Webtechniques that shows you the simple steps on how to do what I said with FrontPage.

http://www.webtechniques.com/archives/1999/09/data/
0
 
webwomanCommented:
FrontPage will definitely do what you want, and very, very fast. However, it won't be nearly as customizable as using other server side languages, and if you're looking to improve your skills, it will do nothing for them (it's a wizard -- a 10 yr old could do it).

Also, if it STOPS working (and guaranteed, it will at some point) you're pretty much reduced to completely redoing the form.
0
 
cheekycjCommented:
if you have access to FP you might have access to ASP too.. if so it is easy in asp.

CJ
0
 
hirschhouseAuthor Commented:
Well, Webwoman, you're right, it is easy to follow the wizard. however, the code it produced is cumbersome and difficult to figure out. not very modifiable. Can someone give me code example for righting to a file?
0
 
a.marshCommented:
But can you use ASP though hirschhouse? Does your web host support it?

Ant

0
 
hirschhouseAuthor Commented:
I'm still waiting for an answer on that a.marsh
0
 
a.marshCommented:
Ok.

:o)

Ant
0
 
hirschhouseAuthor Commented:
NOPE....My ISP will not support ASP or Access DBs!
What do you think I should do? They say they support cgi, Perl & PHP. I don't know anything about these languages! I just want to capture some simple text from an HTML form without using mailto. The reason i don't want to use mailto is it requires an email program on the client computer. ??????

Any help?
0
 
a.marshCommented:
Don't panic PHP is simple...the only question now is that you are talking about email rather than writing to a file... which do you require?

Ant
0
 
daluuCommented:
If you only want to have form data sent to your email, there are pre-made cgi/Perl and PHP scripts on the web that you can use. They should be easy to use and come with some documentation. Of course if you want to customize the script you would need to know the languages above.

Matt's Script Archive is at http://worldwidemart.com/scripts/ is a good place to find such scripts. You'd want to search for mail/form scripts.
0
 
daluuCommented:
There are also websites that will offer form mail services for FREE. All you have to do is sign up and paste their form mailing code (usually just the action="code" part of the form tag) into your form and they will do the processing instead of your hosting provider. No name comes to mind at this time but you can search with the phrase "free form mail service" and you will definitely get a list of providers for you to review.
0
 
hirschhouseAuthor Commented:
a.marsh,
I want to capture data from my form like Name, address, notes. I'm okay with writing it to a server side file or sending it thru email. Which ever is easier????
0
 
dorwardCommented:
I knocked up a quick (and basic) PHP4 script to mail a form to someone a few months ago:

http://www.dorward.uklinux.net/tmp/dormail.php.txt

Just POST the form to that script.
0
 
hirschhouseAuthor Commented:
dorward,
Let me get this clear. I don't know anything about PHP.

I modify $mailto = my@email.com $website = my website $website = my.website.com....

Then on my HTML with the form set the submit button method = "post" action = "http://webserver.com/php.???"

What extension do i give the PHP file?

HH

0
 
dorwardCommented:
Close. The first bit is right, they are just variables - leave the semi-colon and speech marks on each line intact though.

The extension should be "php", that file has .php.txt so that my webserver doesn't interpret it as a script and try to run it.

So you can rename it to

mailscript.php

and then make the action:

http://www.mywebserver.com/mailscript.php
0
 
webwomanCommented:
If all you want is to get the info from you form, find out what the server already has. Chances are excellent that they've got something installed already, have instructions on how to use it, and can help you if you get stuck.

This is a pretty standard thing for web servers to offer. I'd be very surprised if they didn't have something available for you.
0
 
hirschhouseAuthor Commented:
dorward
Im currently developing and testing this form on an IIS5 server. So far i cant get it to send the form anywhere or return the html. when i set the submit method=post it says "The page cannot be displayed." with method=get it returns the entire PHP script in text.????

Do i need to configure something on my server?
will it even work on my w2k iis5 server?
0
 
dorwardCommented:
PHP has to be installed. You can get it from http://www.php.net/ 

I'm pretty sure it will work with IIS.
0
 
hirschhouseAuthor Commented:
dorward,
I installed PHP4.

I'm getting an error message in this line through my web browser
"Warning: Unknown error in d:\inetpub\wwwroot\mailscript.php on line 32"

That line is:
mail("$mailto","[Dormail] New mail from $website","$message",
     "From: Dormail Script <$mailto>");

What is Dormail? is that the problem?
0
 
dorwardCommented:
Dormail is just a string (in this context).

I would guess either that PHP is misconfigured or not set up for emailing.

Check the server logs for the webmasters error message (rather then the users error message which is what you've posted here)
0
 
chromoniumCommented:
hey,

how dare webwomen


[FrontPage will definitely do what you want, and very, very fast. However, it won't be nearly as customizable
as using other server side languages, and if you're looking to improve your skills, it will do nothing
for them (it's a wizard -- a 10 yr old could do it).

Also, if it STOPS working (and guaranteed, it will at some point) you're pretty much reduced to completely
redoing the form. ]

is what you said, im 14 and i can script in most web dev languages, so WHAT do you mean, even a child could it?
0
 
daluuCommented:
Thanks for the points, hirschhouse. I guess you find ASP to meet your needs? Although you say that your ISP doesn't support ASP.

If you still need some help, I here is a simple PHP script that writes to a text file on the server. make sure the text file is writeable by everyone (chmod 777 on unix machines). Below is the script that will process your form data. This script should be named with a .php extension and you should put the url to this file in the action attribute of your form tag. $pcinventory is just a name for the form and the variables with ending with a \t and \n are the names of the form elements (ie <input type=text name="name">) The \n means end the line and go to the next line. The \t means move a tab over before inserting the next data. So the text file is somewhat a tabbed-column database. This script should work if you have PHP configured correctly. All you need to edit is the text file name, rename $pcinventory to whatever you want, and modify the line:

fputs($pcinventory, "$formelementname\t");

to fit the amount of form elements and element names. I'm sure you can understand the rest. This script will also be your confirmation page.

----------
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Thank You - Form Submitted</TITLE>
</HEAD>
<BODY>

<?php
/*
**process form input, save append it to file
*/
$pcinventory = fopen("pcinfodb.txt", "a");
if ($pcinventory)
{
     fputs($pcinventory, "$username\t");
     fputs($pcinventory, "$pcname\t");
     fputs($pcinventory, "$oem\t");
     fputs($pcinventory, "$pctype\t");
     fputs($pcinventory, "$brand\t");
     fputs($pcinventory, "$model\t");
     fputs($pcinventory, "$series\t");
     fputs($pcinventory, "$serial\t");
     fputs($pcinventory, "$srvtag\t");
     fputs($pcinventory, "$expsvcod\t");
     fputs($pcinventory, "$productid\t");
     fputs($pcinventory, "$os\t");
     fputs($pcinventory, "$mem\t");
     fputs($pcinventory, "$memother\t");
     fputs($pcinventory, "$cpu\t");
     fputs($pcinventory, "$cpuother\t");
     fputs($pcinventory, "$hdsize\t");
     fputs($pcinventory, "$hdbrand\t");
     fputs($pcinventory, "$cdrom\t");
     fputs($pcinventory, "$cdbrand\t");
     fputs($pcinventory, "$nicnum\t");
     fputs($pcinventory, "$nicbrand1\t");
     fputs($pcinventory, "$nicbrand2\t");
     fputs($pcinventory, "$ziptype\t");
     fputs($pcinventory, "$zipsize\t");
     fputs($pcinventory, "$monitorbrand\t");
     fputs($pcinventory, "$monitormodel\t");
     fputs($pcinventory, "$monitorsize\t");
     fputs($pcinventory, "$monitorpldate\t");
     fputs($pcinventory, "$officever\t");
     fputs($pcinventory, "$nortonver\t");
     fputs($pcinventory, "$pagemakerver\t");
     fputs($pcinventory, "$pdfver\t");
     fputs($pcinventory, "$iever\t");
     fputs($pcinventory, "$netscapever\t");
     fputs($pcinventory, "$wmver\t");
     fputs($pcinventory, "$realver\t");
     fputs($pcinventory, "$zipver\t");
     fputs($pcinventory, "$other\n");
     fclose($pcinventory);
}

?>

<DIV align="center">
<H3>Thank You for submitting your computer information to our computer inventory database.</H3>

<FORM>
<INPUT type="button" value="Exit this form" onclick="window.close()">
<BR>&nbsp;<BR>
<SPAN style="color: #ff0000; font-weight: bold;">For IT Department use only</SPAN><BR>
<INPUT type="button" value="Add another form entry" onclick="window.location='default.htm'">
</FORM>
</DIV>
</BODY>
</HTML>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 7
  • 5
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now