Necesito poner en una web un formulario o casilla para que quien quiera inscribirse a la web para recibir información, deje sólo su correo electrónico y que éste se guarde automáticamente en una base de datos excel. Como no sé hacer bases de datos he encontrado un archivo php que cumple con los requisitos que necesito, pero no sé cómo adaptarlo a la web. He encontrado este archivo:
Cita:
<?php
/*
apgForm 1.7
By: Alvaro Prieto (apg88)
E-Mail: [email protected]
Web site: http://www.apg88.com/index.php?page=apgForm
Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/legalcode
http://creativecommons.org/licenses/by/2.5/ (Summary)
You can modify the code all you want, make money with it, release newer versions, etc... just leave my name, email, and web site URL on the it.
*/
// Change this to the page you want the user to be redirected to after form is submitted (i.e. success.html and error.html)
$success = "";
$error = "";
// 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
// Don't change anything below this line
// Determine if the form was sent through the GET methog or the POST method.
if($_POST){
$array = $_POST;
} else if($_GET){
$array = $_GET;
} else {
die("You must Access this file through a form."); // If someone accesses the file directly, it wont work :)
}
//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";
}
}
// 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; // If file does not exist, write the header(first line in excel with titles) to the file
}
// 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
// Success
header("Location: $success");
} else {
// Error
header("Location: $error");
}
}
?>
/*
apgForm 1.7
By: Alvaro Prieto (apg88)
E-Mail: [email protected]
Web site: http://www.apg88.com/index.php?page=apgForm
Licensed under the Creative Commons Attribution 2.5 License - http://creativecommons.org/licenses/by/2.5/legalcode
http://creativecommons.org/licenses/by/2.5/ (Summary)
You can modify the code all you want, make money with it, release newer versions, etc... just leave my name, email, and web site URL on the it.
*/
// Change this to the page you want the user to be redirected to after form is submitted (i.e. success.html and error.html)
$success = "";
$error = "";
// 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
// Don't change anything below this line
// Determine if the form was sent through the GET methog or the POST method.
if($_POST){
$array = $_POST;
} else if($_GET){
$array = $_GET;
} else {
die("You must Access this file through a form."); // If someone accesses the file directly, it wont work :)
}
//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";
}
}
// 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; // If file does not exist, write the header(first line in excel with titles) to the file
}
// 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
// Success
header("Location: $success");
} else {
// Error
header("Location: $error");
}
}
?>
La explicación que acompaña este archivo dice lo siguiente:
You will need:
1. A PHP enabled host
2. A folder in your server with read/write permissions to work. (CHMOD 777)
3. Microsoft Excel, OpenOffice, 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 it's in to 777
3. That's it!
apgForm es un archivo PHP capaz de formularios web de transformación y guardarlos directamente en un archivo de Excel.
apgForm recibe ningún tipo con cualquier número de cuadros de texto, botones de radio, menús desplegables, campos ocultos, y las cajas de la contraseña y los guarda en un archivo de Excel.
Puede recibir el formulario, independientemente de la forma en que se envió (POST o GET).
apgForm requiere PHP y una carpeta con permisos de lectura / escritura permisos para trabajar. (CHMOD 777)
¿Cómo se configura esto para la web donde debo insertarlo? y ¿Qué es o qué significa (CHMOD 777)?