New Community Forums are coming. Watch this space for news.
Subscribe: RSS
  • Derrrr... It worked! Nevermind my questions. Oh me of little faith—I tried the 3 step tutorial and it worked. So if you’re reading this and you need eForm data to go into your DB. Them 3 steps is all you have to do.

    I know it’s simple to many but it made this designer feel smart to implement a real smarty pants’s code.
    • Sorry if this going over covered ground, but I’m seeing the "Call to undefined function ’eForm2db’()..." error in my implementation too. I really want this to work! smiley

      Here’s my eForm2db snippet (eForm2dbBanff)
      function eForm2db( &$fields )
      		Version: 0.1 [Beta 1]
      		Author: pixelchutes
      			eForm 1.4+
      			- 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;
      		// Init our array
      		$dbTable = array(); // key = DB Column; Value = Insert/Update value
      		$dbTable['firstname'] = $fields['firstname'];
      		$dbTable['lastname'] = $fields['lastname'];
      		$dbTable['email'] = $fields['email'];
      		$dbTable['phone'] = $fields['phone1'].$fields['phone2'].$fields['phone3'];
      		$dbTable['address'] = $fields['address'];
      		$dbTable['city'] = $fields['city'];
      		$dbTable['state'] = $fields['state'];
      		$dbTable['postal'] = $fields['postal'];
      		$dbTable['gender1'] = $fields['gender1'];
      		$dbTable['size1'] = $fields['size1'];
      		$dbTable['gender2'] = $fields['gender2'];
      		$dbTable['size2'] = $fields['size2'];
      		$dbTable['garments'] = $fields['garments'];
      		$dbTable['activities'] = $fields['activities'];
      		$dbTable['thoughts'] = $fields['thoughts'];
      		$dbTable['optin'] = $fields['optin'];
      		// Insert field/value pairs to insert/update in our table
      		// 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, 'pl_banff_contest' );		
      		return true;
      	return '';

      And here’s the eForm call on a cacheable page
      [!eForm? &runSnippet=`eForm2dbBanff` &formid=`banffContestForm` &noemail=`true` &eFormOnBeforeMailSent='eForm2db' &tpl=`banff-contest-form` &thankyou=`thank-you-contest` &vericode=`1`!]

      and if it’s useful, the test page:
      ModX 1.0.4/eForm

      I’ve just been wrestling with this for a while, and I definitely need some outside advice. I’m hoping it’s something blindingly obvious that I’m overlooking. Thanks in advance!

      • First runSnippet doesn;t exist in the list of parameteres
        &runSnippet=`eForm2dbBanff` -> &eFormOnBeforeMailSent=’eForm2dbBanff’

        Second change
        function eForm2db( &$fields ) -> function eForm2dbBanff( &$fields )

        • Quote from: cipa at Nov 01, 2010, 09:53 PM

          First runSnippet doesn;t exist in the list of parameteres
          &runSnippet=`eForm2dbBanff` -> &eFormOnBeforeMailSent=’eForm2dbBanff’

          Second change
          function eForm2db( &$fields ) -> function eForm2dbBanff( &$fields )

          I got the runSnippet from earlier in the thread, but regardless, I tried calling the eForm2dbBanff snippet separately before the eForm call and got the same result...

          Also to help me understand, I thought the eFormOnBeforeMailSent parameter was supposed to be the function name, and that the function name didn’t have to match the snippet name?
          • You are correct, The snippet can be any name and must contain the function called in the eFormOnBeforeMailSent like:

            [!snippetCall!] [!eForm eFormOnBeforeMailSent=`functionName`!]
            functionName must be exist inside the snippetCall

            • of course I made the unbelievably rookie mistake of using the wrong punctuation in my snippet call. Silly tick mark. Thanks Cipa for your valiant effort to help.

              In other news was this:

              Quote from: pixelchutes at Feb 23, 2010, 01:22 AM

              Quote from: presson83 at Feb 19, 2010, 05:55 PM

              I’ve got checkboxes in my form. When it saves the form data into the DB it just prints the word "ARRAY". How do you save the array of info from a form with checkboxes?

              Try changing the name of your checkboxes to include "[]" at the end.

              name="colors[]" value="Red"
              name="colors[]" value="Blue"
              name="colors[]" value="Green"

              verified to work? I’m still getting ARRAY entered into my database.

              edit: ah figured it out. Just added a foreach loop for the array in question:
               $activitiesList = '';
              		foreach ( $fields['activities'] as $value ) {
                                          $activitiesList = $activitiesList . $value . ' ';

              • Hi!,

                Is it possible to have a page which previews (overview) the saved database fields?
                Also like to export the fields into a CSV file.
                  Evolution user, I like the back-end speed and simplicity smiley
                • Adding

                  <input type="hidden" name="formid" value="user_form" />

                  under the <form> should fix it
                  • I haven’t wrote the whole 11 pages and havent used this before,
                    but for a new project i’d like to have a form which saves some fields into a db
                    AND my client has to be able to download this db or have it previewed on a page.

                    (its still in bevelopment?)

                    Is that possible?
                      Evolution user, I like the back-end speed and simplicity smiley
                    • The code is solid.

                      Here’s a more detailed tutorial inspired by eForm2Db