We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Quote from: joshywood at May 25, 2007, 08:07 AM

    Hey I didn’t see anything in the posts for using this with a database outside of modx.

    Josh

    There’s this information in the Wiki and other forum posts... in a nutshell, just prefix the database name to the table in your $modx->db call..

    e.g.
    $modx->db->select(’field1,field1’,’alt_db.tableName’);
      Mike Reid - www.pixelchutes.com
      MODx Ambassador / Contributor
      [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
      ________________________________
      Where every pixel matters.
      • 14796
      • 59 Posts
      hey,

      sorry I wasn’t as clear, I guess it was a little late smiley

      eform 1.4.3
      modx .95
      eform2b .1

      To clarify:

      I have been able to get the eform2b to work just fine with the modx database. And for this I must say it’s a very simple and great snippet! And this is fine for now.

      I’m projecting my form will be used quite a lot so I wanted to keep it out of the modx database in the same server. So I had originally created a separate database and wanted to store all the information in there. It seems the problem may be that both databases have separate user permissions and that may be causing the difference here (although without eform2db it works fine). I’m going to try what pixelchute has suggested and see if I can
      get it to work in a separate database later.

      Thanks for the info smiley
      • If you require different user permissions for your alternate database, you can reference the wiki example of initiating a 2nd instance of the DBAPI class. This way, you can authenticate a separate database with an alternate login/pass.

        My suggestion only works for users with the same permissions per database. smiley
          Mike Reid - www.pixelchutes.com
          MODx Ambassador / Contributor
          [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
          ________________________________
          Where every pixel matters.
          • 14796
          • 59 Posts
          Hey,

          I’ve been trying the dbapi but I’m having trouble connecting. I’m getting an access denied error:

          Access denied for user ’videouser’@’localhost’ (using password: YES)

          and this is the way I’m calling it:

          $db= new DBAPI($db_host,$db_name, $db_user,$dp_pw);
          


          All the items are passed in through variables. The host should be "localhost" because I’m on the same server, just a different user and database. And when I go to phpmyadmin and check the database out it connects with videouser@localhost.

          Not sure what I’m doing wrong here...?

          Following this I’m directly going into the work like this:
          $dbQuery = $db->insert($dbTable,'tbl_vid_submit');


          Is that the right way?

          Thank you very much for your help, I’ve been meaning to learn this for a while but it’s been really hard to understand the DB:API.

          Josh
            • 14796
            • 59 Posts
            lol...sorry

            it’s been a long few days/nights

            I guess it would help it I actually pass the correct variable names in smiley

            the eForm2db works perfectly with a separate database as well.

            Thanks again for the great snippet and the help with the dbapi.

            • Hi,

              Ive been trying to get this cool snippet to work but seem to be struggling. sad

              I’ve changed in the snippet

              $dbQuery = $modx->db->insert( $dbTable, $table_prefix . ’insertTableName’ );

              to

              $dbQuery = $modx->db->insert( $dbTable, $table_prefix . ’registrations’ );

              but when I submit my form I get an SQL error

              Execution of a query to the database failed - Unknown column ’datetime’ in ’field list’ »
              SQL: INSERT INTO modx_registrations (name,datetime) VALUES(’ ’,’20070604221843’)

              I know that adding a datetime field will fix the above error, but I was kinda hoping eform2db would process all the form post data and add it into mysql maybe I’m just not reading it all right.

              In my form I have the following fields.

              name, address, postcode, email, password

              Thanks

              Aaron.
                http://www.onesmarthost.co.uk
                UK MODX Hosting with love.
              • Unfortunately eform2db does not handle COLUMN creation as you are describing. If you comment out the
                
                		$dbTable[datetime] = date( 'YmdHis', strtotime( $fields[postdate] ) ); // Massage the postdate timestamp to be MySQL insert friendly
                
                
                line of code, you should be all set! (of course, as you stated, you could also add a `datetime` column, however I would recommend using a non-reserved word for column names ( Maybe I should update my example? wink )
                  Mike Reid - www.pixelchutes.com
                  MODx Ambassador / Contributor
                  [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                  ________________________________
                  Where every pixel matters.
                  • 10076
                  • 1,024 Posts
                  Quote from: joshywood at May 25, 2007, 11:00 PM

                  hey,

                  sorry I wasn’t as clear, I guess it was a little late smiley

                  eform 1.4.3
                  modx .95
                  eform2b .1

                  To clarify:

                  I have been able to get the eform2b to work just fine with the modx database. And for this I must say it’s a very simple and great snippet! And this is fine for now.

                  I’m projecting my form will be used quite a lot so I wanted to keep it out of the modx database in the same server. So I had originally created a separate database and wanted to store all the information in there. It seems the problem may be that both databases have separate user permissions and that may be causing the difference here (although without eform2db it works fine). I’m going to try what pixelchute has suggested and see if I can
                  get it to work in a separate database later.

                  Thanks for the info smiley

                  Hi,

                  read that you managed to get things going. I am still struggling a bit. But as this is being developed, perhaps not the time for configuration issues. So I though maybe I can ask you to verify my calls etc?

                  Cheers
                    • 7885
                    • 40 Posts
                    well, i’m not a developer, so understand all the work we need to make for eform2db to work is not easy if it isn’t all in one post ordered step by step, so i decided to help the modx community with this litlle post:

                    first: we make a table named cargas in the modx database
                    CREATE TABLE `cargas` (
                      `id` int(10) unsigned NOT NULL auto_increment,
                      `fullname` varchar(255) NOT NULL,
                      `rut` varchar(15) NOT NULL,
                      `sexo` varchar(5) NOT NULL,
                      `edad` int(1) NOT NULL,
                      PRIMARY KEY  (`id`)
                    ) ENGINE=MyISAM DEFAULT;
                    


                    second: we need a form to send the info to the database, let’s make the nuevaCarga chunk
                    <p class="error">[+validationmessage+]</p>
                    <form method="post" action="[~[*id*]~]" id="nuevaCarga" name="nuevaCarga">
                    	<fieldset>
                    		<label for="cfName">full name:
                    		<p><input name="fullname" id="cfName" class="text" type="text" eform="Your Name::1:"/></p></label> 
                    		<label for="cfEmail">rut:
                    		<p><input name="rut" id="cfEmail" class="text" type="text"/></p> </label> 
                    		<label for="cfRegarding">sexo
                    		<p><input name="sexo" id="sexo" class="text" type="text" eform="Form sexo::1" /></p> </label> 
                    		<label for="cfMessage">edad:
                    		<p><input name="edad" id="edad" class="text" type="text" eform="Form edad::1" /></p> </label>
                    		<label> </label><p><input type="submit" name="contact" id="cfContact" class="button" value="inscribir" /></p> 
                    	</fieldset>
                    </form>
                    


                    third: we make the eForm2db like snippet (this snippet is based on pixelchutes eForm2db, i just adjust to fill the table i used and remove the comments to make the post shorter):
                    <?php
                    function agregarCargas( &$fields )
                    	{
                    		global $modx;
                    		// Init our array
                    		$dbTable = array();
                    		$dbTable[fullname] = $fields[fullname];
                    		$dbTable[rut] = $fields[rut];
                    		$dbTable[sexo] = $fields[sexo];
                    		$dbTable[edad] = $fields[edad];
                    		// Run the db insert query
                    		$dbQuery = $modx->db->insert($dbTable, 'cargas' );
                    		return true;
                    	}
                    ?>
                    


                    fourth:we create a new document with the following snippet calls:
                    [!agregarCargas!] [!eForm? &noemail=`true` &formid=`nuevaCarga` &eFormOnBeforeMailSent=`agregarCargas` &tpl=`nuevaCarga` &thankyou=`3`!]
                    


                    i hope this will work to all in the community, it worked for me! laugh

                    francisco
                    www.dospuntocero.cl
                      visit us at www.dospuntocero.cl
                      • 7923
                      • 4,213 Posts
                      Good job on writing the step by step tuto.. it would be nice if you could make it as an article in the MODx wiki and link to it in the eForm wiki page. Thanks for the contribution.


                        "He can have a lollipop any time he wants to. That's what it means to be a programmer."