We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12846
    • 5 Posts
    I am using eform2db and I have an issue

    if I do not call the eform2db at all then all is OK and my form works, email sends OK and thanks text is displayed.


    If I run my eform snippet duplicated and edited with hard coded values then it will add a line to the database and work fine without errors.

    However if I combine them all, the form submits - the page loads really slow and all I get is a blank screen as if MODx has crashed and died !! huh

    please can someone suggest an idea


    
    <!-- snippet call -->
    
    [[eForm2db]]
    
    [!eForm? &formid=`frmContact` &subject=`A contact form has been filled and submitted from my website` &to=`[*reportEmail*]` &ccsender=`1` &tpl=`webMail` &report=`web_mail_email` &vericode=`1` &fromname=`[email protected]`  &thankyou=`webMail_Thanks`  &eFormOnBeforeMailSent=`eForm2db`!]
    
    
    <!-- the eform2db function looks like this -->
    
    <?php
    function eForm2db( &$fields )
    	{
    		/*---------------------------------------------------------------		
    		eForm2db 
    		Version: 0.1 [Beta 1]
    		Author: pixelchutes
    		---------------------------------------------------------------*/
    
    			  
    	
    
    		// Bring needed resources into scope
    		global $modx, $table_prefix;
    
    
    
    		// Insert field/value pairs to insert/update in our table
          $table_name = $modx->getFullTableName( 'contacts' );
    
          $dbTable = array();
    
    			  $dbTable['contactName'] = $fields['contactName'];
    			  $dbTable['companyName'] = $fields['companyName'];
    			  $dbTable['email'] = $fields['email'];
    			  $dbTable['postCode'] = $fields['postCode'];
    			  $dbTable['telephone'] = $fields['telephone'];
    			  $dbTable['Message'] = $fields['Message'];
    			  $dbTable['Reason'] = $fields['Reason'];
    			  $dbTable['emailNewsletter'] = $fields['emailNewsletter'];
    			  $dbTable['contDated'] = date(ymd).'-'.date(H).':'.date(i);
     
          // Run the db insert query
     
          $dbQuery = $modx->db->insert($dbTable, $table_name );
    
    		
    		
    
    		return true;
    	}
    	// Return empty string
    	return '';
    
    
    
    



    any ideas are gratefully listened to



    thanks
      • 12846
      • 5 Posts
      I thought I’d post this in case anyone else is having the same problem

      check all your spellings in the eForm call snippet

      duplicate your eform2db snipppet and call it something like TTeform2db

      then delete all the content from between the function opening and closing brackets {}
      except the return statements

      <?php
      //functions for eForm events
      function testRun( &$fields ){
      	
      //do nothing
      
      		//return succes
      		return  true;
      }
      //return empty string
      return '';
      ?>
      


      amend your eForm snippet and run it.
      If it still errors then you have an error that is nothing to do with eform2db or the code in that function
      If it runs OK then you know that is where the error is.

      I also made use if the latest eForm update 1.4.6


      if you have been able to set up a test as described in my first post above the you will know if your "insert" statement works or not

      You should be able to logically work it through to a positive outcome.

      remember sometimes it "works almost by accident" when you have stuided the code over and over again and can’t see the fault.

      Make a cup of tea or coffee "go away and come back 10 mins later" and check it all from the top again.
      I copy all snippets into my HTML code editor so I can see then more clearly and check it all.
      If each section runs ok (eForm and the code in the eFrom2db) snippets when you combine them it should also work.
      Read the good docs for eForm found in assets >> snippets >> eForm >> docs >> eform.htm and take it from there

      You may feel like this undecided :’( huh shocked but soon hopefully you ’ll be like this laugh

      enjoy
        • 18250
        • 37 Posts
        Hey everyone.
        Great idea about this snippet and all. I’ve wondered about that a long time, now I wonder even more:
        Is there an easy way to show this kind of table data (or any kind) in manager? Just a simple page where the table is shown with posible delete / edit button for each row?
        I really never understood about modx how could not everybody need that in their pages?
        There’s always about some data in sql tables, which need to be shown / edited via CMS system, so I’m quite confused about that with Modx.

        I know I can write my own plugin for Modx which could do that, but I just can’t believe that noone needed that before me smiley

        I’m I missing something big here? huh

        Thank you guys and keep up the good work!

          • 4172
          • 5,888 Posts
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 18250
            • 37 Posts
            WOW, that looks like the thing I’m looking for smiley wink
            I’ll go and try it right now. cool

            Thank you.
              • 3927
              • 16 Posts
              Hi,

              i always get two new entries in my database, instead of one. The database is on another database and not the modx database

              i have the following code:
              <?php
              if(!function_exists(createDatabaseEntry)) 
              {
              	function createDatabaseEntry( &$fields )	
              	{
              		global $modx;
              
              		//connect to database
              		$modx->db->connect('localhost', xxx, xxx , xxx, true);
              		$result = $modx->db->select("*", "xxx", "scc='" . $fields[scc] . "'");
              
              		if( $modx->db->getRecordCount($res) == 0 )
              		{
              			// Init our array
              			$dbTable = array();
              			$dbTable[scc] = $fields[scc];
              		
              			// Run the db insert query
              			$dbQuery = $modx->db->insert($dbTable, 'xxx' );
              			$modx->db->disconnect();
              		} else
              		{
              			$modx->db->disconnect();
              		}
              		return true;
              	}// end function
              	return '';
              } // end if
              ?>
              


              The snippets calls are
              [!saveToDb!]
              [!eForm? &eformOnBeforeMailSent=`createDatabaseEntry` &noemail=`1` &formid=`addEntry` &tpl=`form_tpl` &thankyou=`mail_tpl`!]
              
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                For one thing, if this is not just a typo in the forum post, you have
                $result = $modx->db->select("*", "xxx", "scc='" . $fields[scc] . "'");
                
                		if( $modx->db->getRecordCount($res) == 0 )

                the variables don’t match. ($result / $res)

                For another thing, you should always quote your string array values:
                $fields['scc']


                  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
                  • 3927
                  • 16 Posts
                  Stupid typo’s. The $results != $res did the trick. Thanks Susan
                    • 5430
                    • 247 Posts
                    Anybody know if there’s a way to pass more than one value to the $modx->db->update "where value"?

                    I’m using a eform2db based snippet to populate/update my template variable content from a form and I’m able to use the "where value" to specify a specific row in the database table to update based on a field value, like this:

                    $dbQuery = $modx->db->update($dbTable, 'modx_site_tmplvar_contentvalues', "contentid=2"');


                    but I need to check one additional value in the table to be sure I’m updating the right row. Specifically, I want to check both the contentid field and the tmplvarid field. I’m extremely new to PHP so forgive me if I’m missing something obvious, but I’m hoping there’s a way to supply two values within the statement itself without using an additional query. Any help? Anybody? Bueller?
                      • 5430
                      • 247 Posts
                      I discovered a solution to my own problem. I didn’t catch on right away that the "where" value is simply a mySQL clause, so something like the following does the trick.

                      $dbQuery = $modx->db->update($dbTable, 'modx_site_tmplvar_contentvalues', "contentid=6 AND tmplvarid=1");


                      This works, and I am happy.