Solved

Writing to a file

Posted on 2001-08-04
30
304 Views
Last Modified: 2006-11-17
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
Comment
Question by:hirschhouse
  • 9
  • 7
  • 5
  • +4
30 Comments
 
LVL 17

Expert Comment

by:dorward
ID: 6352807
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
 
LVL 15

Expert Comment

by:a.marsh
ID: 6352815
That's right - let us know what server-side scripting you have available and we can help you further.

:o)

Ant
0
 

Author Comment

by:hirschhouse
ID: 6352866
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
 
LVL 17

Expert Comment

by:dorward
ID: 6352944
The other question is do you really want to use a file, it could be better to use a database instead.
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6353173
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
 

Author Comment

by:hirschhouse
ID: 6353651
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
 
LVL 17

Expert Comment

by:dorward
ID: 6353687
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
 
LVL 4

Accepted Solution

by:
daluu earned 75 total points
ID: 6353747
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
 
LVL 19

Expert Comment

by:webwoman
ID: 6355619
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
 
LVL 19

Expert Comment

by:cheekycj
ID: 6355934
if you have access to FP you might have access to ASP too.. if so it is easy in asp.

CJ
0
 

Author Comment

by:hirschhouse
ID: 6356261
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
 
LVL 19

Expert Comment

by:cheekycj
ID: 6356283
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6357087
But can you use ASP though hirschhouse? Does your web host support it?

Ant

0
 

Author Comment

by:hirschhouse
ID: 6357212
I'm still waiting for an answer on that a.marsh
0
 
LVL 15

Expert Comment

by:a.marsh
ID: 6357306
Ok.

:o)

Ant
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:hirschhouse
ID: 6358058
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
 
LVL 15

Expert Comment

by:a.marsh
ID: 6358432
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
 
LVL 4

Expert Comment

by:daluu
ID: 6361048
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
 
LVL 4

Expert Comment

by:daluu
ID: 6361066
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
 

Author Comment

by:hirschhouse
ID: 6361304
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
 
LVL 17

Expert Comment

by:dorward
ID: 6361323
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
 

Author Comment

by:hirschhouse
ID: 6361377
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
 
LVL 17

Expert Comment

by:dorward
ID: 6361503
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
 
LVL 19

Expert Comment

by:webwoman
ID: 6361710
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
 

Author Comment

by:hirschhouse
ID: 6365454
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
 
LVL 17

Expert Comment

by:dorward
ID: 6365732
PHP has to be installed. You can get it from http://www.php.net/

I'm pretty sure it will work with IIS.
0
 

Author Comment

by:hirschhouse
ID: 6366043
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
 
LVL 17

Expert Comment

by:dorward
ID: 6366079
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
 

Expert Comment

by:chromonium
ID: 6394167
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
 
LVL 4

Expert Comment

by:daluu
ID: 6399582
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now