Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Sending form variables to a text file

Posted by Anji (Anji), 30 July 2002
The behaviour of text fields when sending field names to a file is different to that of checkbox fields.  Text fields are easy.  I am struggling to send both the names of the checkbox fields and the value of the fields to the text file, being able to send one or the other but not both together.  Also, if the compulsory fields were not completed by the user and the form has to be redisplayed, sending the field names and values behaves differently yet again.  Any suggestions?

Posted by admin (Graham Ellis), 1 August 2002
Indeed the formats of the different field types are different - you need to "thank" the originatiors of HTML forms for that (although they did a pretty good job considering they didn't realise how big this form thing was going to turn out to be!

I've put up a test form with a text field, a chack box, and a selection menu for good measure at:
I've made all the fields "sticky" - in other words, once you fill in a box it will be echoed back that way on the next form.  All entries are simply appended to a log file at the moment, and that log file is echoed back after the form.

Here's the source code:

<head><title>Form Elements to file</title></head>
<body bgcolor=white text=blue>
<H1>Sample form - save fields to file</h1>

// This is a form with "sticky" fields .....

<form method=post>
Text Box <input name=one
  echo (htmlspecialchars(stripslashes($HTTP_POST_VARS["one"])));
  ?>" size=15><br>
Checkbox <input name=two type=checkbox
  if ($HTTP_POST_VARS["two"] != "") echo ("checked");
Select <select name=three>
  $compass = array ("North","South","East","West") ;
  foreach ($compass as $possibility) {
     echo ("<option");
     if ($HTTP_POST_VARS["three"] == $possibility) echo (" selected");
     echo (">$possibility");
<input type=submit>

// Save all the fields on any previous form to a file

$fh = fopen("../testdata","a");
fputs($fh,$HTTP_POST_VARS["one"]." - ".
  $HTTP_POST_VARS["two"]." - ".
  $HTTP_POST_VARS["three"]." - ".time().

// Echo the file contents onto the end of the form

$stuff = implode("",file("../testdata"));
echo (nl2br(htmlspecialchars(stripslashes($stuff))));



This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho