We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20744
    • 19 Posts
    I sorted out the error on the mail part. It they &to call was adding a mailto wrapper around the email address and was messing up the code. I had to go into code and remove it manually. the eForm2db still does not seem to write to the database though. I get no error. Just no content added to the DB.
      • 26182
      • 164 Posts
      from your code it looks like you are adding two prefixes - one with the table name and another through a parameter in the modx call to insert data into the database i.e. mox_table_name is preceeded by modx table prefix parameter - this is adding the prefix twice so your result is modx_modx_table_name. try removing the modx_ from your table name.
        • 12461
        • 22 Posts
        Hello, I am having quite a strange problem.
        I implemented the eform2db locally and it works fine.
        Then I copied all the nescessary files online and set up the database-table the same way as on the local system.
        Whey i try to open the file with the form I get the following error-Message:


        Fatal error: Cannot redeclare eform2db() (previously declared in /homepages/4/*****/htdocs/*****/manager/includes/document.parser.class.inc.php(769) : eval()’d code:2) in /homepages/4/*****/htdocs/*****/manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 2

        Here is the code I use to call the form:

        [[eForm2db]]
        [!eForm? &noemail=`true` &formid=`registrierung` &eFormOnBeforeMailSent=`eForm2db` &tpl=`registrierung_formular` &thankyou=`registrierung_danke` !]

        I´ll be gratefull for any idea.

        Thank you,

        Henry
          • 29030
          • 27 Posts
          Is there a way to select a different database with this script? From what I see, this uses the default modx database. I’d rather not use that.
            • 7231
            • 4,205 Posts
            Yes, just change the MODx api stuff ($result = $modx->db->query($sql);) to the standard PHP
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don't know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 20744
              • 19 Posts
              Hi, I still haven’t managed to write to my database. I have kind of given up on it. I noticed that most of the eForm2db seem to be set to noemail=’true’ is that required or is it possible to have it both sending the email and writing to the database. Could that be the reason, I thought everything else seemed OK.

              Does anybody know if there is a way of writing the form fields to a csv file instead?

              Thanks again for your help
                • 20744
                • 19 Posts
                I have decided to try one more time to see if I can get it to work. Here is what I have. MY database table is called modx_form_results and is located in the default Modx Database.

                Database Fields

                Field= con_id, Type=int(10), Null=No, Extra=auto_increment
                Field= con_name, Type = varchar Null=Yes
                Field= con_email, Type = varchar Null=Yes
                Field= con_company, Type = varchar Null=Yes
                Field= con_query, Type=longtext Null=Yes
                Field= con_date, Type = timestamp Null=No, Default =Current_timestamp

                My snippet code is as follows
                <?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;
                
                // Init our array
                $dbTable = array(); // key = DB Column; Value = Insert/Update value
                
                // Insert field/value pairs to insert/update in our table
                $dbTable[con_name] = $fields[name]; // Name Field
                $dbTable[con_email] = $fields[email]; //email
                $dbTable[con_company] = $fields[company]; //company
                $dbTable[con_date] = date( 'YmdHis', strtotime( $fields[postdate] ) ); // Massage 
                
                the postdate timestamp to be MySQL insert friendly
                $dbTable[con_query] = $fields[query]; //query
                
                
                // 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[form_results].'\'', '' );
                // etc...
                				
                // Run the db insert query
                $dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'form_results' );		
                
                return true;
                }
                // Return empty string
                return '';
                ?>
                


                The call from the page is as follows:

                Call from the page:
                
                [[eForm2db]] 
                
                [!eForm? &formid=`ContactForm` &to=`[email protected]` eFormOnBeforeMailSent=`eForm2db` &tpl=`ContactForm` report=`ContactFormReport`  &thankyou=`ContactFormThanks` &subject=`Web site feedback` &cssStyle=`assets/templates/mystyle.css` !] 
                
                

                I am not an expert at MODx as you can guess and I must be doing something totally stupid as everybody else seems to get this working very easilly.

                Thanks again for your help. Let me know if you see something obvious. I have been looking at this for too long.
                  • 10076
                  • 1,024 Posts
                  Quote from: hugofrosch at Apr 09, 2008, 05:04 AM

                  Hello, I am having quite a strange problem.
                  I implemented the eform2db locally and it works fine.
                  Then I copied all the nescessary files online and set up the database-table the same way as on the local system.
                  Whey i try to open the file with the form I get the following error-Message:


                  Fatal error: Cannot redeclare eform2db() (previously declared in /homepages/4/*****/htdocs/*****/manager/includes/document.parser.class.inc.php(769) : eval()’d code:2) in /homepages/4/*****/htdocs/*****/manager/includes/document.parser.class.inc.php(769) : eval()’d code on line 2

                  Here is the code I use to call the form:

                  [[eForm2db]]
                  [!eForm? &noemail=`true` &formid=`registrierung` &eFormOnBeforeMailSent=`eForm2db` &tpl=`registrierung_formular` &thankyou=`registrierung_danke` !]

                  I´ll be gratefull for any idea.

                  Thank you,

                  Henry

                  Hi I am not an expert, but so far in the examples on previous pages in this post the &tpl and &formid seem to have the same value/name. Also actually on my page, where it seems to work okay. Maybe give that a try?
                    • 21783
                    • 5 Posts
                    I really like Modx and the community that supports it. Everything I know about php I learned from reading this forum, so my logic and code is full of holes. I have been working on a ’store locator’ script for 4 weeks, and after reading pages and pages of the forum I finally got it to work.
                    I would like to share what I did, but I worry that because I copied so much code from the google maps tutorial (really cut and paste) that there might be a problem.
                    The script allows ’Brokers’ to add themselves to a database, then after I verify the data (and insert their lat. and long. based on their street address), a person can go to a map, choose a radius and up comes a google map with markers, names and distances.
                    I also don’t understand a few things that I did, like why in eform, people put a ’cf’ or an ’s’ in front of the name of the field and id, so I just copy what they do. (oh yeah, and I get an error code -only- when I run the script on another page when logged in the manager.)
                    3 questions: can people cut and paste code from a tutorial and use it freely, and, I see that members who know what they are doing, post their code in neat windows or colored boxes, how is that done, and is there an interest in a store locator script that probably is not really coded well- except for what I ’borrowed’?
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      1. Yes,

                      2. click on the # icon in the menu and it will insert the code tags,

                      3. and we love to share  grin grin

                      the prefixes for the fields are just a way to keep track of which form you’re talking about. It lets you code for multiple forms without getting confused as to which one should be what value. "cf" probably means "contact form".
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org