writing out data to a text file from a HTML form

R

Ron Smith

What I want to do is create a HTML form that allows the user to enter data
into about 10 fields, and then based on the entered data, writes out data
strings to a text file. I am attempting to create a form for entering
simple rectangle CAD data via a HTML form, which will be written to a text
file, and then imported into a CAD program.

The form would contain prompt boxes for things like length, width, radius
size, step/repeat, etc. When the user hits the "SUBMIT" button, the data
strings would be written out to the filename the user specified. Below is
an example of data strings to be ouputted. Variables are &L, &W, &R,
&STEPX, &STEPY, &XN, &YN.

FRO 0 0 BY &L 0 ATT 1 POI 2
BY 0 &W ATT 1 POI 2
BY -&L,0 ATT 1 POI 2
TO 0 0 POI 2
JOI EXT 1 2 BLE &R
JOI EXT 2 3 BLE &R
JOI EXT 3 4 BLE &R
JOI EXT 4 1 BLE &R
TRY;SEC LAYOUT;REC;LAYOUT;YRT
SUB A POS 0 0 ATT 0;FILE A INT
MER A TO A
TRY;COP 1 BY &STEPX 0 TIM &XN-1;REC;YRT
TRY;COP .. BY 0 &STEPY TIM &YN-1;REC;YRT
 
D

Dave Patton

What I want to do is create a HTML form that allows the user to enter
data into about 10 fields, and then based on the entered data, writes
out data strings to a text file.

Make the target of the form be a PHP script that takes the
form inputs and writes the text file.
 
W

William Park

Ron Smith said:
What I want to do is create a HTML form that allows the user to enter data
into about 10 fields, and then based on the entered data, writes out data
strings to a text file. I am attempting to create a form for entering
simple rectangle CAD data via a HTML form, which will be written to a text
file, and then imported into a CAD program.

The form would contain prompt boxes for things like length, width, radius
size, step/repeat, etc. When the user hits the "SUBMIT" button, the data
strings would be written out to the filename the user specified. Below is
an example of data strings to be ouputted. Variables are &L, &W, &R,
&STEPX, &STEPY, &XN, &YN.

FRO 0 0 BY &L 0 ATT 1 POI 2
BY 0 &W ATT 1 POI 2
BY -&L,0 ATT 1 POI 2
TO 0 0 POI 2
JOI EXT 1 2 BLE &R
JOI EXT 2 3 BLE &R
JOI EXT 3 4 BLE &R
JOI EXT 4 1 BLE &R
TRY;SEC LAYOUT;REC;LAYOUT;YRT
SUB A POS 0 0 ATT 0;FILE A INT
MER A TO A
TRY;COP 1 BY &STEPX 0 TIM &XN-1;REC;YRT
TRY;COP .. BY 0 &STEPY TIM &YN-1;REC;YRT

I don't understand. User types 'abc' into a form box, and you print it
out to a file. What is your question, exactly?

If this is question about how to print inside CGI, then take a look at
sample CGI script found on your machine or on Internet.
 
R

Ron Smith

William Park said:
I don't understand. User types 'abc' into a form box, and you print it
out to a file. What is your question, exactly?

If this is question about how to print inside CGI, then take a look at
sample CGI script found on your machine or on Internet.

Sorry for the confusion. User types in values (numbers) for length, width,
and radius size of a rectangle, how many they want, and the step/repeat
value of the rectangle matrix. The code (resulting text file) which you
highlighted is created from the data inputted by the user, and later, this
text file is imported into a CAD program.
 
H

Hywel

What I want to do is create a HTML form that allows the user to enter data
into about 10 fields, and then based on the entered data, writes out data
strings to a text file. I am attempting to create a form for entering
simple rectangle CAD data via a HTML form, which will be written to a text
file, and then imported into a CAD program.

What server-side processing do you have? ASP? CGI? PHP?
 
T

Toby Inkster

Ron said:
Thanks a lot. That is exactly what I was looking for.

No worries.

I did forget to mention one particular gotcha though -- your web host has
to support server-side scripting in some language. (I used PHP in the
example, but doing the same thing in Perl, Python, JSP or ASP would be
smiple.) Nowadays most hosts do support some kind of server-side scripting
(except most free hosting packages).
 
R

Ron Smith

Toby Inkster said:
No worries.

I did forget to mention one particular gotcha though -- your web host has
to support server-side scripting in some language. (I used PHP in the
example, but doing the same thing in Perl, Python, JSP or ASP would be
smiple.) Nowadays most hosts do support some kind of server-side scripting
(except most free hosting packages).
I downloaded and installed an Apache webserver, with PHP. Being new to
both, I am having trouble figuring out how to associate the two files (HTML
form screen and PHP file), in regards to file location and filename. ie.
Where do I place them on my local server so Apache can find them? I
couldn't figure out how you did it, but I assume the hander-src file has a
..PHP extension.
 
T

Toby Inkster

Ron said:
I downloaded and installed an Apache webserver, with PHP.

You do realise that PHP needs to be installed on your web server, not on
your desktop computer? (Though for some people, like me, your desktop
computer *is* your web server!)
Being new to both, I am having trouble figuring out how to associate the
two files (HTML form screen and PHP file), in regards to file location
and filename. ie. Where do I place them on my local server so Apache
can find them? I couldn't figure out how you did it, but I assume the
hander-src file has a .PHP extension.

This file <http://examples.tobyinkster.co.uk/cad/handler-src> is a red
herring -- the real engine is at
<http://examples.tobyinkster.co.uk/cad/handler> but you won't be able to
see it, because the actual PHP code that does the work never gets sent to
the browser. That's why I put a highlighted *copy* of the source code at
<http://examples.tobyinkster.co.uk/cad/handler-src>

The form's "action" attribute should point to the handler.php file. The
handler.php file should contain this code:

<?php
header("Content-Type: text/plain");

$L = $_GET['L'];
$W = $_GET['W'];
$R = $_GET['R'];
$STEPX = $_GET['STEPX'];
$STEPY = $_GET['STEPY'];
$XN = $_GET['XN'];
$YN = $_GET['YN'];
?>
FRO 0 0 BY <?= $L ?> 0 ATT 1 POI 2
BY 0 <?= $W ?> ATT 1 POI 2
BY -<?= $L ?>,0 ATT 1 POI 2
TO 0 0 POI 2
JOI EXT 1 2 BLE <?= $R ?>
JOI EXT 2 3 BLE <?= $R ?>
JOI EXT 3 4 BLE <?= $R ?>
JOI EXT 4 1 BLE <?= $R ?>
TRY;SEC LAYOUT;REC;LAYOUT;YRT
SUB A POS 0 0 ATT 0;FILE A INT
MER A TO A
TRY;COP 1 BY <?= $STEPX ?> 0 TIM <?= $XN ?>-1;REC;YRT
TRY;COP .. BY 0 <?= $STEPY ?> TIM <?= $YN ?>-1;REC;YRT
 
R

Ron Smith

Toby Inkster said:
You do realise that PHP needs to be installed on your web server, not on
your desktop computer? (Though for some people, like me, your desktop
computer *is* your web server!)

I have a program called XAMPP for Windows (webserver) with PHP - both are
running as a local host on my desktop. I need to figure out how to run the
HTML file through XAMPP. XAMPP has a status screen that tells me it is
running, and PHP can be interpreted.
 
S

Sam Hughes

I have a program called XAMPP for Windows (webserver) with PHP - both
are running as a local host on my desktop. I need to figure out how
to run the HTML file through XAMPP. XAMPP has a status screen that
tells me it is running, and PHP can be interpreted.

In your address bar, type in "localhost" or "127.0.0.1".
 
R

Ron Smith

Sam Hughes said:
In your address bar, type in "localhost" or "127.0.0.1".
When I do that, I am able to run XAMPP as a local host. I can input my
values in the form, but the values are not being interpreted by the PHP
file. I guess I am confused with how PHP files are called from an HTML
file. I couldn't find any reference to the handler-src PHP file in the file
form.html
 
T

Toby Inkster

Ron said:
I couldn't find any reference to the handler-src PHP file in the file
form.html

As I said...

| This file <http://examples.tobyinkster.co.uk/cad/handler-src> is a red
| herring -- the real engine is at
| <http://examples.tobyinkster.co.uk/cad/handler> but you won't be able to
| see it, because the actual PHP code that does the work never gets sent
| to the browser. That's why I put a highlighted *copy* of the source code
| at <http://examples.tobyinkster.co.uk/cad/handler-src>
|
| The form's "action" attribute should point to the handler.php file.
 
R

Ron Smith

Toby Inkster said:
As I said...

| This file <http://examples.tobyinkster.co.uk/cad/handler-src> is a red
| herring -- the real engine is at
| <http://examples.tobyinkster.co.uk/cad/handler> but you won't be able to
| see it, because the actual PHP code that does the work never gets sent
| to the browser. That's why I put a highlighted *copy* of the source code
| at <http://examples.tobyinkster.co.uk/cad/handler-src>
|
| The form's "action" attribute should point to the handler.php file.
Thanks Toby. I got confused on the handler-src filename.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top