We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14372
    • 49 Posts
    I posted this ... (as the snippet) ...

    <?php
    
    /* Add ah_postings package */
    
    $path = MODX_CORE_PATH . 'components/ah_postings/';
    $result = $modx->addPackage('ah_postings',$path . 'model/','vw_ah_pos_');
    
    /* Create new posting object */
    
    $position = $modx -> newObject('Postings');
    
    if (!is_object($position) || !($position instanceof xPDOObject)) {
        $errorMsg='Failed to create object of type:Postings ';
        $hook->addError('error_message',$errorMsg); 
        return false;
    }
    
    return true;


    As per your suggestion in an attempt to see if its the object not being created ...

    snippet call still has

    &hooks = `snippetname,email`


    And I had this piece of code in my form ...

    [[!+fi.error_message:notempty=`<div id="update-message">[[!+fi.error_message]]</div>`]]
    [[!+fi.successMessage:notempty=`<div id="update-message">[[!+fi.successMessage]]</div>`]]


    I still got a success message and the email was sent ... from my understanding, that means that the snippet above ran successfully and return a value of true? Yes ... correct me if I’m wrong

      • 14372
      • 49 Posts
      Made some little progress (in regards to debugging) ... using your (Bruno17) idea of verifying if everypart of the code was working I came up with this

      <?php
      
      /* Add ah_postings package and throw an error if unsuccessful */
      $path = MODX_CORE_PATH . 'components/ah_postings/';
      $result = $modx->addPackage('ah_postings',$path . 'model/','vw_ah_pos_');
      
      if (! $result) {
        $errorMsg='Failed to add package ';
        $hook->addError('error_message',$errorMsg); 
        return false;
      }
      
      /* Create new posting object & check if object was created or else throw an error */
      $position = $modx -> newObject('Postings');
      
      if (!is_object($position) || !($position instanceof xPDOObject)) {
          $errorMsg='Failed to create object of type:Postings ';
          $hook->addError('error_message',$errorMsg); 
          return false;
      }
      
      /* Set data from form */
      
      $position->set('usr', $_POST['usr']);
      
      /* Save data from form and throw out errors if fails */
      
      if (!$position->save()) {
          $errorMsg='Failed to save object ';
          $hook->addError('error_message',$errorMsg); 
          return false;
      }
      else
          return true;


      That way we can tell EXACTLY where the snippet is failing.

      I happened to get the ’Failed to save object’ message after trying to submit the form ... which means the adding the package, creating the object went fine until I tried to save just one field ... the usr field. I have a placeholder on my form

      Placeholder in form: [[fi.usr]]
      Database field name: usr


      Any ideas? smiley At least there’s some little progress, just need to figure out why it isn’t saving.
        • 4172
        • 5,888 Posts
        what’s the content of your postings.map.inc.php?
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 14372
          • 49 Posts
          Its ...

          <?php
          $xpdo_meta_map['Postings']= array (
            'package' => 'ah_postings',
            'version' => '1.1',
            'table' => 'postings',
            'fields' => 
            array (
              'id' => NULL,
              'usr' => NULL,
              'department' => NULL,
              'duration' => NULL,
              'renumeration' => NULL,
              'apply-method' => NULL,
              'interns' => NULL,
              'date' => NULL,
            ),
            'fieldMeta' => 
            array (
              'id' => 
              array (
                'dbtype' => 'int',
                'precision' => '10',
                'attributes' => 'unsigned',
                'phptype' => 'integer',
                'null' => false,
                'index' => 'pk',
              ),
              'usr' => 
              array (
                'dbtype' => 'int',
                'precision' => '10',
                'attributes' => 'unsigned',
                'phptype' => 'integer',
                'null' => false,
              ),
              'department' => 
              array (
                'dbtype' => 'varchar',
                'precision' => '255',
                'phptype' => 'string',
                'null' => false,
              ),
              'duration' => 
              array (
                'dbtype' => 'int',
                'precision' => '10',
                'attributes' => 'unsigned',
                'phptype' => 'integer',
                'null' => false,
              ),
              'renumeration' => 
              array (
                'dbtype' => 'int',
                'precision' => '1',
                'attributes' => 'unsigned',
                'phptype' => 'integer',
                'null' => false,
              ),
              'apply-method' => 
              array (
                'dbtype' => 'int',
                'precision' => '1',
                'attributes' => 'unsigned',
                'phptype' => 'integer',
                'null' => false,
              ),
              'interns' => 
              array (
                'dbtype' => 'int',
                'precision' => '100',
                'phptype' => 'integer',
                'null' => false,
              ),
              'date' => 
              array (
                'dbtype' => 'varchar',
                'precision' => '10',
                'phptype' => 'string',
                'null' => false,
              ),
            ),
            'indexes' => 
            array (
              'PRIMARY' => 
              array (
                'alias' => 'PRIMARY',
                'primary' => true,
                'unique' => true,
                'type' => 'BTREE',
                'columns' => 
                array (
                  'id' => 
                  array (
                    'length' => '',
                    'collation' => 'A',
                    'null' => false,
                  ),
                ),
              ),
            ),
          );


          And thanks for you help.
            • 22019
            • 390 Posts
            Probably irrelevant, but your placeholder should be [[+fi.usr]] (just in case it’s a required field and it can’t find a usr value to save, hence failing).
              Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
              • 14372
              • 49 Posts
              Still failed even after setting this line to ...

              $position -> set('usr', $_POST['fi.usr']);
                • 22019
                • 390 Posts
                Bruno has more experience in this area, but it looks to me like your map is set to require all the fields (’null’ => false), and you are only trying to save the usr field (assuming it’s getting a value to save) - so the object will fail to save.
                  Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
                  • 4172
                  • 5,888 Posts
                  seems your id-field isn’t autoincremental in your table.

                  in this case you need to set a unique id by yourself or set it to autoincrement.

                  I think, when trying
                  $position -> set('id', '999');
                  this will work, but only once.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 30319
                    • 406 Posts
                    I want to know more about this -- can this kind of code submit data to authorize.net AND save certain data to a table for later review??
                    Plus send a nice email thanking for the donation??

                    Thank you, Tom