Home arrow PHP arrow PHP Form to Text File: the Basics

PHP Form to Text File: the Basics

This is a basic tutorial on the application of PHP to get text information from a web form and write it to a text file.

TABLE OF CONTENTS:
  1. PHP Form to Text File: the Basics
  2. Processing inputs from submitted form and writing the text to a file
  3. Code discussion
  4. Adding Four Features to the Basic Web Application
  5. Adding features, continued
By: Codex-M
Rating: starstarstarstarstar / 3
July 20, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

This article will illustrate a number of features to be included in this application which are useful in actual project implementations, such as:

  • Restriction of user input to text while blocking unwanted and malicious form inputs.
  • Limiting the number of words of input that can be written to the file.
  • Allowing users to download the written file after text input.
  • Setting a forced download after clicking the download link.

Basic Code Implementation

Before discussing the application features in detail, let's start with the most basic implementation, which does not contain the four additional functions listed above. The basic job is limited to:

1. Show web form to the user.

2. Get posted values from the web form and validate user inputs as to whether or not they're empty.

3. Write text to file (.txt).

Showing the web form if it has not already been submitted 

<?php

 

//Check if the web form is NOT submitted

if (!$_POST['submit'])

 

{

 

//Form is not submitted, display web form

 to the browser

?>

 

<h2>Enter any text below to write to a text file(limited to 200 words)</h2>

 

<form action="<?php echo $SERVER['PHP_SELF']; ?>"

 

method="post">

 

<br />

 

<textarea name="textinputs" rows="25" cols="60"></textarea>

 

<br />

 

<input type="submit" name="submit" value="Write this text to a text file">

 

</form>

 

<a href="/phpformtotextfilebasic">Click here to reset or clear this form</a>

 

<br />

 

<br />

This is what the web form will look on the browser:

 

 



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: