Você está na página 1de 5

<html>

<head><title>
<?php

//Code by apg88 "apgForm(toExcel) 1.4"


// Determine if the form was sent through the GET methog or the POST method.
if($_GET){
$array = $_GET;
}else if($_POST){
$array = $_POST;
} else {
echo "You must Access this file through a form.";

// If someone accesses the file directly, it

wont work :)
}

if(!$array['title']){
// if the title wasnt sent through the form, it will become whatever you set it equal to in the next line
$array['title'] = "apgForm";

//Set default title to be displayed

}
echo $array['title'] .'</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>';

//Check if the filename was sent through the form or not


if(!$array['filename']){
// if the filename wasnt sent through the form, it will become form.xls, you can change the default if
you want.
$array['filename'] = "form.xls"; //Set the file to save the information in

} else {
if(!(stristr($array['filename'],".xls"))){
$array['filename'] = $array['filename'] . ".xls";
}
}

// Change this to whatever you want the users to see after the form i s processed
$continue = ' Here is a the Comment form your info was just sent to <a href="test.xls">Click
Here</a> to see the excel file.<br> <a href = "index.php">Click Here</a> To Return to apgForm ';

// Change this to the character(s) you want to be placed instead of line breaks(new line, enter, etc)
$lbChar = " ";

// default is a space, you may change it to whatever you want

//------------------------------------------------------------------------------------//----------------You do not need to change anything below this line------------------//-------------------------------------------------------------------------------------

// Define the tab and carriage return characters:


$tab = "\t";

//chr(9);

$cr = "\n";

//chr(13);

if($array){
// Make The Top row for the excel file and store it in the $header variable
$keys = array_keys($array);
foreach($keys as $key){
if(strtolower($key) != 'filename' && strtolower($key) != 'title'){
$header .= $key . $tab;
}
}
$header .= $cr;

//Make the line with the contents to write to the excel file.
foreach($keys as $key){
if(strtolower($key) != 'filename' && strtolower($key) != 'title'){

$array[$key] = str_replace("\n",$lbChar,$array[$key]);
$array[$key] = preg_replace('/([\r\n])/e',"ord('$1')==10?'':''",$array[$key]);
$array[$key] = str_replace("\\","",$array[$key]);
$array[$key] = str_replace($tab, " ", $array[$key]);

$data .= $array[$key] . $tab ;


}
}
$data .= $cr;

if (file_exists($array['filename'])) {
$final_data = $data;

//if the file does exist, then only write the information the

user sent
} else {
$final_data = $header . $data;
line in excel with titles) to the file

//if file does not exist, write the header(first

}
// open the file and write to it

$fp = fopen($array['filename'],"a"); // $fp is now the file pointer to file $array['filename']

if($fp){

fwrite($fp,$final_data); //Write information to the file


fclose($fp);

// Close the file

echo "Form Received Successfully! <br> " . $continue;


} else {
echo "Error receiving form! <br>" . $continue;
}
}
//Copyright 2004 apg88. All Rights Reserved
?>

</body>
</html>

apgForm 1.4
-----------------------------------------------------------------------------------------------------------Site: http://www.apg88.com/apgForm/
Email: apgForm@apg88.com
-------------------------------------------------------------------------------------------------------------

You will need:


1. A PHP enabled host (running PHP 4)
2. A folder in your server with read/write permissions to work. (CHMOD 777)
3. Microsoft Excel or a similar program that can open xls files.

Installation:
1. make any changes you need to apgform.php
2. upload it to your server and CHMOD the folder its in to 777
3. That's it!

apgForm is a PHP file capable of processing web forms and saving them directly into an Excel file.
apgForm receives any form with any number of textboxes, radio buttons, drop-down menus, hidden fields, and
password boxes and saves them to an Excel file.
apgForm can receive the form regardless of the way it was sent (POST, or GET.)
The file is named form.xls by default, but can be specified by sending a hidden field with the name of the file. For
example, putting this on the form would make the file test.xml
<input type="hidden" name="filename" value="test">.
apgForm is completely free!

apgForm 1.4 Release Notes:


apgForm now works with tabs in the text fields without altering the cells in the excel file.

apgForm 1.3 Release Notes:


Fixed bugs in the Title and Filename exceptions.

apgForm 1.2 Release Notes:


Added feature that removes the escape character "\" from the posted data.

apgForm 1.1 Release Notes:


apgForm now receives the page title to be received when the form is loaded. The title is what goes in the
<title></title> tags in html.

The excel file doesnt mess up with line breaks (enter, new line, etc). It replaces the line brakes with a user defined
character or characters; it is a space by default.

Current Issue(s):
apgForm does not support the use of checkboxes. I am(still) tryi ng to fix that, and will update as soon as I can.

Copyright 2004 apg88.

Você também pode gostar