We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41430
    • 7 Posts
    Im having an issue with formit2db. I have created the DB table, and ran the create classes page using the XPDO snippet, but i just keep getting the error "cannot create class of type:" every time the form is submitted, although it is still sending via email. As far as i can see i have done everything right, ive done it exactly as stated in the tutorial and it has worked on previous websites i have built.

    Thanks.
      • 3749
      • 24,544 Posts
      Do you have a call to loadClass() somewhere in the process, before the communication with the DB?


      Does the table exist in the DB?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 41430
        • 7 Posts
        The table definitely exists. I've used your XPDO classes tutorial exactly as it was written apart from changing the package name and prefix. and the formit2DB package has just been installed without any modification and the only properties i need to specify are the prefix, package name and table name, which i have done. Not sure what you mean about loadClass().
          • 3749
          • 24,544 Posts
          Sorry, I was confusing loadClass() and addPackage(), one of which has to be called before you can use a custom DB table.


          Formit2DB calls loadPackage() with the properties you send it, but it doesn't check the return value.

          I would change this line in the snippet code:

          $modx->addPackage($packagename, $modelpath, $prefix);


          to something like this:

          if (! $modx->addPackage($packagename, $modelpath, $prefix)) {
              die('<br />addPackage() failed' . 
                 '<br />PACKAGENAME: ' . $packagename . 
                 '<br />MODELPATH: ' . $modelpath . 
                 '<br />PREFIX: ' . $prefix);
          }
          


          That will tell you if the class is being loaded successfully. If it's not, something is probably wrong with one of the three properties you're sending.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 41430
            • 7 Posts
            I did this, and i got an error.the package name was blank so i replaced &packageName with &packagename and it went back to giving me this error:

            "Failed to create object of type:"

            here is my form code

            <h1>Get a quote</h1>
            <p>Simply fill in this form below and one of our Swimsure advisers will contact you to discuss your requirements and provide a quote to meet your needs. Fields marked <span>*</span> are mandatory.</p>
            <p> </p>
            <p>[[!FormIt? &hooks=`email, formit2db` &preHooks=`db2formit`
            &prefix=`modx_`
            &packageName=`quote`
            &tablename=`quoteform` &prefix=`modx_` &packagename=`quote` &tablename=`quoteform` &emailTpl=`sentEmailTpl` &emailSubject=`Swimsure Website Quote` &emailTo=`[email protected]` &successMessage=`</p>
            <h2>Thank You</h2>
            <p>Thank you for submitting a quotation request, we will be back in touch very soon.</p>
            <p>` &successMessagePlaceholder=`fi.successMessage` &validate=`club_name:required, prop_name:required, contact_name:required, phone_no:required:isNumber, contact_email:required:email`]]</p>
            <p>[[!+fi.successMessage:empty=`</p>
            <p>[[+fi.error.error_message]]</p>
            <form id="contactForm" class="cmxform" action="[[~[[*id]]]]" method="post">
            <div><label for="club_name"><span>*</span>Name of Club/School</label>[[!+fi.error.club_name:notempty=`<span class="error">Error: Please enter the name of your Club/School.</span>`]] <input id="club_name" class="required [[!+fi.error.club_name:notempty=`error`]]" type="text" name="club_name" value="[[!+fi.club_name]]" size="30" /></div>
            <div><label for="prop_name"><span>*</span>Proprietors Name</label> [[!+fi.error.prop_name:notempty=`<span class="error">Error: Please enter the proprietors name.</span>`]]<input id="prop_name" class="required [[!+fi.error.prop_name:notempty=`error`]]" type="text" name="prop_name" value="[[!+fi.prop_name]]" size="30" /></div>
            <div><label for="trading_name">Trading Name</label> <input id="trading_name" class="required" type="text" name="trading_name" value="[[!+fi.trading_name]]" size="30" /></div>
            <div><label for="contact_name"><span>*</span>Person to Contact</label> [[!+fi.error.contact_name:notempty=`<span class="error">Error: Please enter the name of the persons to contact.</span>`]]<input id="contact_name" class="required [[!+fi.error.contact_name:notempty=`error`]]" type="text" name="contact_name" value="[[!+fi.contact_name]]" size="30" /></div>
            <div><label for="phone_no"><span>*</span>Phone No</label> [[!+fi.error.phone_no:notempty=`<span class="error">Error: Please enter a valid phone number.</span>`]]<input id="phone_no" class="required [[!+fi.error.phone_no:notempty=`error`]]" type="text" name="phone_no" value="[[!+fi.phone_no]]" size="30" /></div>
            <div><label for="contact_email"><span>*</span>E-Mail </label> [[!+fi.error.contact_email:notempty=`<span class="error">Error: Please enter a valid E-mail address.</span>`]]<input id="contact_email" class="required email [[!+fi.error.contact_email:notempty=`error`]]" type="text" name="contact_email" value="[[!+fi.contact_email]]" size="30" /></div>
            <div><label for="contact_address">Correspondence Address</label> <textarea id="contact_address" class="required" name="contact_address">[[!+fi.contact_address]]</textarea></div>
            <div><label for="renew_data">Policy Renewel Date (if known)</label> <input id="renew_date" class="required" type="text" name="renew_date" value="[[!+fi.renew_date]]" size="30" /></div>
            <div><input class="submit" type="submit" name="submit" value="Submit" /></div>
            </form>
            <p>`]]</p>



            Here is the create classes code i used:

            [[!CreateXpdoClasses? &myPackage=`quote` &myPrefix=`modx_`]]


            and the CreateXpdoClasses snippet was exactly as in your tutorial. The table name is modx_quoteform.

            Is there anything obvious i'm missing?
              • 3749
              • 24,544 Posts
              Can you paste the actual error message in here? I can't find either of the ones you've quoted.

              Did you try running this code from the tutorial?

              <?php
              $path = MODX_CORE_PATH . 'components/quotes/';
              $result = $modx->addPackage('quotes',$path . 'model/','bobs_');
              if (! $result) {
                return 'failed to add package';
              } else {
                $output = '<p>added Package</p>';
              }
              
              $quotes = $modx->getCollection('Quotation'); 
              
              $output .= '<p>Total: '. count($quotes) . '</p>';
              
              foreach($quotes as $quote) {
              
                  $output .= '<p>Topic: ' . $quote->get('topic');
                  $output .= '<br />Quote: ' . $quote->get('quote');
                  $output .= '<br />Author: ' . $quote->get('author') . '<br /></p>';
              }
              
              return $output;
              
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 41430
                • 7 Posts
                "Failed to create object of type:" this is the actual error im getting. I can see the reference to it in the formit2db snippet but cant work out whats causing it.

                The code you pasted wont working because im using a different table structure.

                To be honest i think i might just leave it this time, there is no reason for it not to be working and im going to just try it on the next website i build.

                Thanks for your help!
                  • 3749
                  • 24,544 Posts
                  I took a quick look at the code, it appears that Formit2DB is not getting the class name from the table. IOW, this line is failing:

                  $classname = $generator->getClassName($tablename); 


                  I'm not sure why.

                  This is the function code:

                  public function getClassName($string) {
                      if (is_string($string) && $strArray= explode('_', $string)) {
                          $return= '';
                          while (list($k, $v)= each($strArray)) {
                              $return.= strtoupper(substr($v, 0, 1)) . substr($v, 1) . '';
                          }
                          $string= $return;
                      }
                      return trim($string);
                  }
                  
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 41430
                    • 7 Posts
                    Hi Bob,

                    Thanks for your help, it seems there was some issue with the formit2db and db2formit snippets downloaded through package manager. I copied the code from an older site we built and it worked first time.

                    Thanks again.