We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27376
    • 576 Posts
    Quote from: BullDER at Feb 01, 2008, 12:43 AM

    ...
    I’m tryin’ next code:
    [!eForm2db!]
    [!eForm? &noemail=`true` &formid=`contact` &eFormOnBeforeMailSent=`eForm2db` &tpl=`contactform` &thankyou=`contactthanks` !]
    ...
    I’m uderstand that it’s troblu only cause itsn’t see function eForm2db( &$fileds) ... but how it fix???
    What does the code in your [tt][!eForm2db!][/tt] snippet look like? The [tt]&eFormOnBeforeMailSent[/tt] parameter doesn’t take a snippet name, it takes a function, which means that a [tt]function() {}[/tt] must be defined before the [tt]eForm[/tt] snippet is called. Also, depending on your PHP version, functions names will be case-sensitive. I’ve also found that sometimes if there is an error in your code, MODx will silence it and you won’t know it until some peculiar error comes up like the one you are seeing.
      • 4290
      • 10 Posts
      snippet contain identical code like in first post...

      <?php
      	function eForm2db( &$fields )
      	{
      		global $modx, $table_prefix;
      		$dbTable = array(); // key = DB Column; Value = Insert/Update value
      		$dbTable[name] = $fields[first_name].' '.$fields[last_name]; // Merge two form fields together
      		$dbTable[datetime] = date( 'YmdHis', strtotime( $fields[postdate] ) ); // Massage the postdate timestamp to be MySQL insert friendly
      		$dbQuery = $modx->db->insert( $dbTable, $table_prefix . 'my_table' );		
      
      		return true;
      	return '';
      ?>


      And create table with needs columns... check case... check spell... check alll... but on snippet eForm andrew on it... they talkin’ that can’t see define function eForm2db... i’m try it on hosting.. try it local.. no chance (((

      And i try include that function in eform.inc.php ... but itsn’t help... I’m tired... so easy snippet.. but I can’t let him work...
      try turn eForm for send on mail... but it too doesn’t help me (((

      I hope that some fresh idea break my burn out...
        • 27376
        • 576 Posts
        Quote from: BullDER at Feb 01, 2008, 09:14 AM

        snippet contain identical code like in first post...
        Your code is missing the closing ’}’ bracket in between the return.
          • 14909
          • 8 Posts
          Hi - I’m trying to add a duplicate check function into eform2db to make sure a user can only submit the form one time and I can’t seem to get it to work. Here is the code I’m using. The sql returns the right result

          <?php
          function entry2db( &$fields )
          {
          global $modx;
          //check if already entered
          $sql = "select * from `modx_entries` where `email` = ’".$fields[’email’]."’");

          $result = $modx->db->query($sql);
          return $result;

          $num = mysql_num_rows($result);


          if( $num > 0 )
          {
          // Set placeholders
          $chunkArr = array(’dupe_entry’ => ’It appears you have already entered the contest. Only one entry per person is allowed. If you have a question or feel there is a problem please contact us at <a href="mailto:[email protected]">[email protected]</a>. Thank you.’);

          Output the dupe alert
          echo $modx->parseChunk( ’dupe_entry_tpl’, $chunkArr, ’[+’, ’+]’ );
          // Prevent form load
          return true;
          }else
          {
          // Init our array
          $dbTable = array();
          $dbTable[name] = $fields[name];
          $dbTable[email] = $fields[email];
          $dbTable[highschool] = $fields[highschool];
          $dbTable[address] = $fields[address];
          $dbTable[address2] = $fields[address2];
          $dbTable[city] = $fields[city];
          $dbTable[state] = $fields[state];
          $dbTable[zip] = $fields[zip];
          $dbTable[phone] = $fields[phone];
          $dbTable[idea] = $fields[idea];
          // Run the db insert query
          $dbQuery = $modx->db->insert($dbTable, ’modx_entries’ );
          return true;
          }
          }

          ?>

          Any help greatly appreciated
            • 4290
            • 10 Posts
            Quote from: sirlancelot at Feb 01, 2008, 11:51 AM
            Your code is missing the closing ’}’ bracket in between the return.

            Yeah yeah ssory... it’s just my mistake... forget about ’}’ and.. put space after exlamation
              • 22289
              • 41 Posts
              I love eform2DB, and have successfully gotten it to return a set of my records from a table of contacts by following awardle’s example on page 6 of this thread, and pixelchute’s advice to use the parseChunk method...

              <?php
              
              $contact_base = isset($contact_base) ? $modx->config['base_path'].$contact_base : $modx->config['base_path']."assets/snippets/contact/";
              
              // include some pagination code...
              $files = array (
              	"main_class" => $contact_base."classes/paginate.inc.php"
              );
              
              // Select all records
              $dbase = 'mydatabase.contact';
              $contacts = $modx->db->select('*',$dbase);
              
              		$output= "<ul id=\"contact\">";	
              
              		while( $row = $modx->fetchRow( $contacts ) ){
              		
              				$id=$row['ID'];
              				$first=$row['FIRST'];
              				$last=$row['LAST'];
              				
              				$chunkArr = array(
              				
              					'contactid' => $id,
              					'firstname' => $first,
              					'lastname' => $last
              								
              				);
              
              // send this to mycontacts chunk				
              				$output .= $modx->parseChunk('mycontacts', $chunkArr, '[+', '+]');
              
              }
              
              $output .= "</ul>";			
              
              
              return $output;
              
              
              ?>
              
              


              but what I am now wondering is whether anyone has figured out how to paginate the set of results. Originally I thought looking at Ditto might help, but it’s pretty advanced for me. I may be stumbling in the right direction by including this old paginate file I found here:

              http://svn.modxcms.com/trac/tattoo/browser/tattoo/trunk/manager/includes/paginate.inc.php?rev=3281

              but don’t immediately know enough about php offhand to know how to apply this to my results... So, I guess I was just wondering if I was reinventing the wheel or if anyone else had figured out a way to do this.

                • 26182
                • 164 Posts
                Hi,

                I’ve just installed this snippet and I get this error:


                Fatal error: Call to undefined function: eform2db() in E:\hshome\arterial\arterial.com.au\microsite\assets\snippets\eform\eform.inc.php on line 386

                Does anyone know how to fix this?

                Thanks!


                Sarah
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  You have the snippet tags in your content before the eform snippet tags?
                    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
                    • 20744
                    • 19 Posts
                    Hi,
                    I am having the same problem trying to use the eForm2db snippet and adding to a database table. I am getting the error Fatal error: Call to undefined function eForm2db().

                    I called the snippet before the eForm call on the content page and used the standard eForm2db snippet code.

                    Did you resolve the issue or any ideas as to what is going wrong?
                      • 26182
                      • 164 Posts
                      hey it had something to do with caching i think but first check that your eform2db and see that it reflects all the values in your form and in your db table.

                      try using [!eForm2db?!] or [!eForm2db!] or [[eForm2db]] and see which one works if that doesn’t work out.

                      grin