We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37589
    • 12 Posts
    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.]
    • Did you try placing your hook before email in the hooks parameters?

      &hooks=`spam,FormitDump,email,FormItAutoResponder,redirect`
      


      Remember hooks are processed in the order they are in the &hooks not sure if that will solve your issue but it's worth a try.

      Good luck.
        Benjamin Marte
        Interactive Media Developer
        Follow Me on Twitter | Visit my site | Learn MODX
        • 37589
        • 12 Posts
        Quote from: benmarte at Mar 20, 2013, 07:53 PM
        Did you try placing your hook before email in the hooks parameters?

        &hooks=`spam,FormitDump,email,FormItAutoResponder,redirect`
        


        Remember hooks are processed in the order they are in the &hooks not sure if that will solve your issue but it's worth a try.

        Good luck.
        I've tried changing the order of the hooks, tried moving the hooks up/down the lines but I'm still getting the same error. Any other ideas?
        • Have you checked your error log to see if there are any clues as to where in the process it is failing?

          Also try adding this placeholder somewhere on your page to see if it spits out any errors as well.

          [[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]
          
            Benjamin Marte
            Interactive Media Developer
            Follow Me on Twitter | Visit my site | Learn MODX
            • 37589
            • 12 Posts
            Quote from: benmarte at Mar 21, 2013, 01:48 PM
            Have you checked your error log to see if there are any clues as to where in the process it is failing?

            Also try adding this placeholder somewhere on your page to see if it spits out any errors as well.

            [[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]
            

            Its not spitting any errors out
            -> [[!+fi.error_message:notempty=`<p>[[!+fi.error_message]]</p>`]]


            I found a quick save script that already qorks with modx, but now the form is just not working altogether. I have tried installing and re-installing it again. I'm going to try to install an earlier release of formit and see if that works.

            It's just very frustrating as MODx seems to cache everything I try to do on top of this.
              • 37589
              • 12 Posts
              Alright, well it turned out to be an issue with our exchange server after I had uninstalled, reinstalled, and uninstall everything a million times.