We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10164
    • 27 Posts
    Hi Dimmy + Subd
    Can you give any more information about the file paths
    I have downloaded the snippet and i’m calling it with my form template, i am receiving emails with an image attachment, but my modx database has no new tables ??
    somehow this is working but i cant figure out where it is storing the files.
    my snippet...
     <?php
    function eForm2db( &$fields )
    
    	{
    
    		/*---------------------------------------------------------------		
    
    		eForm2db 
    
    		Version: 0.1 [Beta 1]
    
    		Author: pixelchutes
    
    		---------------------------------------------------------------
    
    		Requirements:
    
    			eForm 1.4+
    
    		---------------------------------------------------------------
    
    		Use:
    
    			- Takes validated eForm submittal data for use with the MODx DBAPI extender class.								
    
    			- Easily process database records referencing your form submission data:				  
    
    			  + INSERT new records to a table of your choice				  
    
    			  + UPDATE existing records if you'd prefer				  
    
    			  + DELETE records based on form submittal criteria				  
    
    			  + Form a query and return its record set as XML using $modx->db->getXML				  
    
    			  + Query a table's MetaData using $modx->db->getTableMetaData, followed by an update query
    
    			    on only the form fields that are named after table columns!				    
    
    			  + and much more! 
    
    		---------------------------------------------------------------*/
    
    
    
    		// Bring needed resources into scope
    
    		global $modx, $table_prefix, $_FILES;
    
    
    
    if($fields['naam']&&$_FILES['image_name']){
    
    
    
    // move number for to yes or no for sms
    
    if($ifields['sms'] == 1){$ifields['sms'] = "ja";}else{$ifields['sms'] = "nee";}
    
    
    
    //maak filename voor kleine foto
    
    $filename= "/home/glamprod/public_html/assets/fotowedstijd/".$fields['naam'].".jpg";
    
    $filepath = "/home/glamprod/public_html/assets/uploads/".$fields['naam'].".jpg";
    
    
    
    // als file al bestaat plaats er een timestamp achter
    
    $tijd = time();
    
    if (file_exists($filename)) {
    
    $filename = "/home/glamprod/public_html/assets/fotowedstijd/".$fields['naam'].$tijd.".jpg";
    
    $filepath = "/home/glamprod/public_html/assets/uploads/".$fields['naam'].$tijd.".jpg";
    
    }
    
    
    
    // pak orgineel bestand en geef deze een naam
    
    $filename_groot = "/home/glamprod/public_html/assets/fotowedstijd/".$fields['naam']."_groot.jpg";
    
    $filepath_groot = "/home/glamprod/public_html/assets/uploads/".$fields['naam']."_groot.jpg";
    
    
    
    // als file al bestaat plaats er een timestamp achter
    
    if (file_exists($filename_groot)) { 
    
    $filename_groot = "/home/glamprod/public_html/assets/fotowedstijd/".$fields['naam'].$tijd."_groot.jpg";
    
    $filepath_groot = "/home/glamprod/public_html/assets/uploads/".$fields['naam'].$tijd."_groot.jpg";
    
    }
    
    
    
    // geef de paden van de geuploade bestanden terug aan eform zodat deze in de database gescherven kunnen worden
    
    
    
    // begin image manupulation
    
    include('assets/snippets/fotowedstrijd/snapshot.class.php'); 
    
    $myimage = new ImageSnapshot; 
    
    $myimage->Width = 165; 
    
    $myimage->Height = 190; 
    
    $myimage->Resize = true; 
    
    $myimage->ResizeScale = 100; 
    
    $myimage->Position = 'center'; 
    
    $myimage->Compression = 80;
    
    $myimage->ImageField = $_FILES['image_name'];
    
    
    
    // geef de file aan de image processor voor schalen
    
    $myimage->SaveImageAs($filename);
    
    
    
    //sla orgineel bestand op
    
    copy($_FILES['image_name']['tmp_name'], $filename_groot);
    
    
    
    // pas de rechten aan zodat de bestanden gedouwnload kunnen worden.
    
    chmod ($filename, 0755);
    
    chmod ($filename_groot, 0755);
    
    
    
    // end image manipulation
    
    $fields['image'] = $filepath;
    
    $fields['foto_groot'] = $filepath_groot;
    
    //unset($fields['image']);
    
    
    
    		// Init our array
    
    		$dbTable = array(); // key = DB Column; Value = Insert/Update value
    
    
    
    	// Grab our table's columns
    
    	$tblColumns = array_keys( $modx->db->getTableMetaData( 'modx_fotowedstrijd' ) );
    
    	
    
            // Loop through each column, and insert it if present in the form
    
    	foreach( $tblColumns as $tblCol )
    
    		if( isset( $fields[ $tblCol ] ) ) $dbTable[ $tblCol ] = $fields[ $tblCol ];
    
    
    
    
    
    		// Insert field/value pairs to insert/update in our table
    
    	        $dbTable[image] = $filepath; 
    
                    $dbTable[foto_groot] = $filepath_groot ;
    
    
    
    		// INSERT - $dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'insertTableName' );
    
    		// UPDATE - $dbQuery = $modx->db->update( $dbTable, $table_prefix . 'updateTableName' );
    
    		// DELETE - $dbQuery = $modx->db->delete( $table_prefix . 'deleteFromTableName', 'some_field = 1 AND name=\''.$dbTable[name].'\'', '' );
    
    		// etc...
    
    				
    
    		// Run the db insert query
    
                   $dbQuery = $modx->db->insert( $dbTable, 'modx_fotowedstrijd' );
    
    
    
    		return true;
    
    	}
    
    }
    
    	// Return empty string
    
    	return '';
    ?> 


    my form template...
     [+validationmessage+] 
    <form action="[~[*id*]~]" id="EmailForm" method="post" name="EmailForm" enctype="multipart/form-data">
    	<fieldset>
    	<h3>Male Models</h3>
    	<input name="formid" type="hidden" value="ContactForm" />
    	<label for="cfName">Your name:
    	</label>
    	<p>
    	<input class="text" id="cfName" name="name" type="text" />
    	</p>
    	<label for="cfPhone">Contact number:
    	</label>
    	<p>
    	<input class="text" id="cfPhone" name="phone" type="text" />
    	</p>
    	<label for="cfEmail">Your Email Address:
    	</label>
    	<p>
    	<input class="text" id="cfEmail" name="email" type="text" />	
    	</p>
            <label for="cfDob">Your Date of Birth:
            </label>
            <p>
            <input class="text" id="cfDob" name="dob" type="text" />
    	</p>
            <label for="cfheight">Height:
            </label>
            <p>
            <input class="text" id="cfheight" name="height" type="text" />
    	</p>
            <label for="cfwaist">Waist:
            </label>
            <p>
            <input class="text" id="cfwaist" name="waist" type="text" />
    	</p>
            <label for="cfsuit">Suit Size:
            </label>
            <p>
            <input class="text" id="cfsuit" name="suit" type="text" />
    	</p>
    <p><label accesskey="i" for="image_name">Image</label>
    <input name="image_name" type="file"   />
    </p>
    
    
    
    	<p>
    	Please tell us a little bit about yourself and if you have any modelling or dancing experience .
    	</p>
    	<label for="cfMessage">Message:
    	</label>
    	<p>
    	<textarea cols="50" id="cfMessage" name="message" rows="15"></textarea>
    	</p>
    	<p>
    	Please enter the verification code below: (to prevent spam)<br />
    	<br />
    	<img src="[+verimageurl+]" />
    	<input name="vericode" size="20" type="text" />
    	</p>
    	<label> </label>
    	<p>
    	<input class="button" id="cfContact" name="contact" type="submit" value="Send This Message" />
    	</p>
    	</fieldset>
    </form>
    


    and my snippet call...
    [!eForm2db!]
    [!eForm? &eFormOnBeforeMailSent=`eform2db` &formid=`ContactForm` &subject=`[+subject+] [+naam+]` &to=`[email protected]` &tpl=`MaleForm` &report=`upload_report` &vericode=`1` &gotoid=`74` !] 
    


    Any help would be much appreciated smiley

      • 21257 MODX Staff
      • 730 Posts
      Just a reply to the original question posed at the top of this thread.
      There is no "correct" way to do it in MODx, other than I guess to make sure it works and does not create any security problems.
      I tend to write custom form handling snippets, and when it comes to storing data, I use xPDO. It took a little while for me to learn this, but it’s definitely been worth the time, because how the form processor works and what it does is 100% up to me. (Also, since I’m not designing a general solution for the world, writing a form processor, or form controller, can be very quick.)

      The other side to this question that I don’t think has been addressed (or maybe it was never asked) is what do you do with the data once it’s in the database?
      I’m actually quite curious about the various ways that people handle data that’s being stored to custom tables, what they do with the data, and how are the end users getting at that data? Maybe I should take that into another thread?
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 7455
        • 2,204 Posts
        Quote from: netProphET at Jul 25, 2008, 10:25 AM

        The other side to this question that I don’t think has been addressed (or maybe it was never asked) is what do you do with the data once it’s in the database?
        I’m actually quite curious about the various ways that people handle data that’s being stored to custom tables, what they do with the data, and how are the end users getting at that data? Maybe I should take that into another thread?

        I created another snippet that acts a bit like ditto in a way that you get placeholders from each field in the db that can be used in a chunk and called by the snippet
        that way yopu can present the data in any way you want.
        I also made a small module where the client can see a overvieuw of all the images in the db including all the info.
        and an option to export that to csv.

        Dimmy
          follow me on twitter: @dimmy01
          • 10164
          • 27 Posts
          @ Dimmy
          can you share the module and snippet for viewing and administering the files uploaded?
          i have managed to get the eform to attach a image file, but my DB has no new tables ?? how can this be , i can not see where the images are being stored, but they are there on the server somewhere huh
          Any ideas
          Thanks