I have created a new snippet and added it as a hook lets call it "FormitDump" in the formit below.
Snippet Purpose: is to get the form post data, create a txt file and dump the results of the post.
Snippet Result: is I can't get the email to send out if my new hook is running.
[[!FormIt? &hooks=`spam,email,FormItAutoResponder,[b]FormitDump[/b],redirect` &emailTpl=`formEmail` &emailTo=`[email protected]` &emailSubject=`Contact Form Submission - [[++site_name]]` &redirectTo=`6` &fiarTpl=`formAuto` &fiarSubject=`[[++site_name]] Contact Form Submission` &fiarFrom=`[email protected]` &customValidators=`securityCode` &store=`1` &validate=`nospam:blank, name:required, email:email:required, comments:required:stripTags, securityCode:required:securityCode`]]
<?php
# Attached is my class
$data = $hook->getValues();
$postfields = newformdump();
$postfields->get_form_fields($data);
return true;
?>
The attachments aren't working for me, so here is the custom script:
<?php
/*---------------------------------------------------
MODX INSTALL INSTRUCTIONS
1. Create Snippet called 'FormitDump'
2. Add the follow code to your snippet
<?php
$data = $hook->getValues();
include 'scripts/store-form-data.php';
return true;
?>
3. Add your store-form-data.php file to the scripts folder
4. Add your snippet 'FormitDump' to the hooks right after 'email'
[[!FormIt? &hooks=`spam,email,FormitDump,FormItAutoResponder,redirect`
5. DONE!!!
NON-MODX INSTALL INSTRUCTIONS
1. Uncomment Line 30 //if(!empty($_POST)){$data = $_POST;} else {$data = $fields;}
2. Add your store-form-data.php file to the scripts folder
3. Add the follow code to the top of your sendmail code
<?php
include(scripts/store-form-data.php);
?>
4. DONE!!!
---------------------------------------------------*/
# Identify if coming from post form or modx
//if(!empty($_POST)){$data = $_POST;} else {$data = $fields;}
# Create new object and pass data to be processed
$postfields = new formdump();
$postfields->get_form_fields($data);
# Checks how old files are and delete
$remove = new filemanagement();
$remove->remove_files();
class formdump
{
var $fields;
var $path;
var $timestamp;
var $mailfile;
function get_form_fields($f)
{
# Dump path
$this->path = str_replace('public_html', '', $_SERVER['DOCUMENT_ROOT']).'mail_dump/';
# Fields array
$this->fields = $f;
# Create current timestamp for file
$this->timestamp = date("Y-m-d-H-i-s");
# Check if mail folder exists / Create mail folder
if(file_exists($this->path))
{
# Directory exists
$dirgood = 1;
}
else
{
# Make dump folder if does not exist
mkdir($this->path, 0755);
# Directory made
$dirgood = 1;
}
if($dirgood == 1)
{
# Put file together
$encoded = '------- Submitted Form -------' . "\r\n";
$counter = 0;
# Loop through array and clean up for file
foreach($this->fields as $key=>$value)
{
if($value)
{
$encoded .= '"'.$key.'" : "'.$value.'"' . "\r";
$counter++;
}
}
# Trim returning string
$string = rtrim($encoded, ',');
# Create file and write to it
$this->mailfile = $this->path.'mail-'.$this->timestamp.'.txt';
$handle = fopen($this->mailfile, 'w') or die("can't open file");
fwrite($handle, $string);
fclose($handle);
}
}
}
class filemanagement
{
var $dir;
function remove_files()
{
$seconds = 217728000; // 1 year 217728000
# Path to remove files
$this->dir = str_replace('public_html', '', $_SERVER['DOCUMENT_ROOT']).'mail_dump/';;
if(!$dirhandle = @opendir($this->dir)){ return;}
# Loop through files in mail_dump folder
while(false !== ($filename = readdir($dirhandle)))
{
if($filename != "." && $filename != "..")
{
$filename = $this->dir. "/". $filename;
if(@filemtime($filename) < (time()- $seconds))
{
# If a file greater than seconds old then delete
@unlink($filename);
}
}
}
}
}
?>
[ed. note: onaboat last edited this post 11 years, 1 month ago.]