We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11055 ☆ A M B ☆
    • 3,112 Posts
    Try change:
    $scriptProperties[’quoteId’] = !empty((int) $_GET[’quoteId’]) ? (int) $_GET[’quoteId’] : ’’;

    to be this:
    $scriptProperties[’quoteId’] = !empty($_GET[’quoteId’]) ? intval($_GET[’quoteId’]) : ’’;
      Rico
      Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
      MODx is great, but knowing how to use it well makes it perfect!

      www.virtudraft.com

      Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

      Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

      Maintainter/contributor of Babel

      Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
      • 25226
      • 29 Posts
      Thanks... Now its not giving an error, but still does not post to db
        • 11055 ☆ A M B ☆
        • 3,112 Posts
        Is
        <?php
        
        die(print_r($_POST));
        

        empty?
          Rico
          Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
          MODx is great, but knowing how to use it well makes it perfect!

          www.virtudraft.com

          Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

          Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

          Maintainter/contributor of Babel

          Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
          • 25226
          • 29 Posts
          I apologize, im not quote sure what your wanting me to do. un commented the die(print_r($_POST));
          and it didnt do anything.

          also, it just seems really weird that the url is changing between hitting submit

          This is my code

          <?php
          
          /* EditQuote Snippet */
          
          // You might want to use this instead
          $scriptProperties['quoteId'] = !empty($_GET['quoteId']) ? intval($_GET['quoteId']) : '';
          if (empty($scriptProperties['quoteId'])) {
              // or you want to echo out any text
              return '';        
          }
          
          /* Get the existing Quote */
          $path = MODX_CORE_PATH . 'components/quotes/';
          $result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
          $quote = $modx->getObject('Quotation', array('id'=>$scriptProperties['quoteId']));
          
          
          
          if (isset($_POST['submit']) && ($_POST['submit'] == 'submit')) {
              /**
               * Try to see whether the field's values are empty or not, using:
               * die(print_r($_POST));
               */
              /* Form has been submitted */
              // @todo sanitize the input values, this is IMPORTANT!
          
          
              $quote->set('topic', $_POST['topic']);
              $quote->set('quote', $_POST['quote']);
              $quote->set('author', $_POST['author']);
          
          
              if ($quote->save()) {
                  $output = "Quote Created";
              } else {
                  $output = "Error";
              }
          } else {
             /* Not a repost, just display the form */
          
              /* The second argument to getChunk() tells MODx to replace
               * the placeholders with the existing quote's values
               */
              $output = $modx->getChunk('quotationTplEdit', $quote->toArray());
          }
          return $output;
          


          this is my form chunk

          <form method="post" action="[[~[[*id]]]]">  
                         <input type="hidden" name="quoteId" value="[[+id]]" />
                          <p>Author: <input type="text" name='author' id='author' value="[[+author]]" /></p>                
                         <p>Author: <input type="text" name='topic' id='topic' value="[[+topic]]" /></p>
                          <p>Author: <input type="text" name='quote' id='quote' value="[[+quote]]" /></p>
                          <input type='submit' name='submit' id='submit' value='submit'/>
          
          </form>


          and on my editform resource page I just call the snippet like this [[EditQuote]]
            • 11055 ☆ A M B ☆
            • 3,112 Posts
            hang on,
            what resources did you make to deal with this form?
            new form? edit form? report form?

            or are they on the same resource, and switched by $_GET trigger?
              Rico
              Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
              MODx is great, but knowing how to use it well makes it perfect!

              www.virtudraft.com

              Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

              Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

              Maintainter/contributor of Babel

              Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
              • 25226
              • 29 Posts
              Here is the complete process. Thank you again for helping.

              "ShowQuotes" resource page
              [[ShowQuotes]]
              


              which points to
              "ShowQuotes" snippet
              <?php
              $path = MODX_CORE_PATH . 'components/quotes/';
              $result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
              
              
              $quotes = $modx->getCollection('Quotation');
              
              $output .= '<p>Total: ' . count($quotes) . '</p>';
              
              foreach ($quotes as $quote) {
              
              $output .= $modx->getChunk('quoteTpl', $quote->toArray());
              /* "quoteTpl above gives html layout for "Edit" link */
              }
              
              return $output;


              "quoteTpl" chunk refered above
              Author: [[+author]]<br />
              Quote: [[+quote]]<br />
              Topic: [[+topic]]<br />
              <a href="[[~41]] ?quoteId=[[+id]]">Edit</a><br />
              


              which shows a list of records for the user to select one to edit. Upon selecting a record. Triggers:
              "FormEdit" resource page WHICH HAS A RESOURCE ID OF 41(refered to in above code)
              [[EditQuote]]


              which points to
              "EqitQuote" snippet
              <?php
              /* EditQuote Snippet */
              
              // You might want to use this instead
              $scriptProperties['quoteId'] = !empty($_GET['quoteId']) ? intval($_GET['quoteId']) : '';
              if (empty($scriptProperties['quoteId'])) {
                  // or you want to echo out any text
                  return '';        
              }
              
              /* Get the existing Quote */
              $path = MODX_CORE_PATH . 'components/quotes/';
              $result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
              $quote = $modx->getObject('Quotation', array('id'=>$scriptProperties['quoteId']));
              
              
              
              if (isset($_POST['submit']) && ($_POST['submit'] == 'submit')) {
                  /**
                   * Try to see whether the field's values are empty or not, using:
                   * die(print_r($_POST));
                   */
                  /* Form has been submitted */
                  // @todo sanitize the input values, this is IMPORTANT!
              
              
                  $quote->set('topic', $_POST['topic']);
                  $quote->set('quote', $_POST['quote']);
                  $quote->set('author', $_POST['author']);
              
              
                  if ($quote->save()) {
                      $output = "Quote Created";
                  } else {
                      $output = "Error";
                  }
              } else {
                 /* Not a repost, just display the form */
              
                  /* The second argument to getChunk() tells MODx to replace
                   * the placeholders with the existing quote's values
                   */
                  $output = $modx->getChunk('quotationTplEdit', $quote->toArray());
              }
              return $output;


              which populates the form from
              "quotationTplEdit" chunk
              <form method="post" action="[[~[[*id]]]]">  
                             <input type="hidden" name="quoteId" value="[[+id]]" />
                              <p>Author: <input type="text" name='author' id='author' value="[[+author]]" /></p>                
                             <p>Author: <input type="text" name='topic' id='topic' value="[[+topic]]" /></p>
                              <p>Author: <input type="text" name='quote' id='quote' value="[[+quote]]" /></p>
                              <input type='submit' name='submit' id='submit' value='submit'/>
              
              </form>
                • 11055 ☆ A M B ☆
                • 3,112 Posts
                First of all, please check whether you have all the needed files as Bob stated on his tutorial:

                quotes
                model
                quotes
                mysql
                quotation.class.php
                quotation.map.inc.php
                quotation.class.php
                schema
                quotes.mysql.schema.xml
                If you do not have quotation.map.inc.php file, you can not continue. It’s dead here.
                You must jump to the bottom section of that tutorial about making the Mapping file.
                I haven’t generated the mapping, but my quick guess about the content is:
                <?php
                $xpdo_meta_map['Quotation']= array (
                  'package' => 'quotes',
                  'table' => 'bobs_quotation',
                  'fields' => 
                  array (
                    'quote' => '',
                    'author' => '',
                    'topic' => '',
                  ),
                  'fieldMeta' => 
                  array (
                    'quote' => 
                    array (
                      'dbtype' => 'mediumtext',
                      'phptype' => 'string',
                      'null' => false,
                    ),
                    'author' => 
                    array (
                      'dbtype' => 'varchar',
                      'precision' => '200',
                      'phptype' => 'string',
                      'null' => false,
                      'default' => '',
                    ),
                    'topic' => 
                    array (
                      'dbtype' => 'varchar',
                      'precision' => '20',
                      'phptype' => 'string',
                      'null' => false,
                      'default' => '',
                    ),
                  ),
                );
                

                Or else, Bob?

                "ShowQuotes" snippet
                <?php
                $path = MODX_CORE_PATH . 'components/quotes/';
                $result = $modx->addPackage('quotes', $path . 'model/', 'bobs_');
                /**
                 * when the database becomes big, you may consider to add limit to the query, before you fetch the getCollection.
                 * @link http://rtfm.modx.com/display/XPDO10/xPDOQuery.limit
                 * modx extends the xPDO, so all the xPDO methods can be used directly:
                 */
                $criteria = $modx->newQuery('Quotation');
                $quotes = $modx->getCollection('Quotation', $criteria);
                
                $output = ''; // goldsky: before it's continuously appended below, it should be emptied first.
                //$output .= '<p>Total: ' . count($quotes) . '</p>';
                // use count as below
                // @link http://rtfm.modx.com/display/XPDO10/xPDO.getCount
                $output .= '<p>Total: ' . $modx->getCount('Quotation') . '</p>';
                
                foreach ($quotes as $quote) {
                    /* quoteTpl above gives html layout for "Edit" link */
                    $output .= $modx->getChunk('quoteTpl', $quote->toArray());
                }
                
                return $output;


                "quoteTpl" chunk refered above
                Author: [[+author]]<br />
                Quote: [[+quote]]<br />
                Topic: [[+topic]]<br />
                <a href="[[~41? &scheme=`full` &quoteId=`[[+id]]` ]]">Edit</a><br />
                

                I just like the &scheme=`full`, for absolute URL. It’s a personal preference, though.
                See how I add the &quoteId argument to the snippet.
                MODx is smart, it will add anything but &scheme as additional arguments to the URL.

                Quote from: robb at Feb 27, 2011, 11:47 PM

                which shows a list of records for the user to select one to edit. Upon selecting a record. Triggers:
                "FormEdit" resource page WHICH HAS A RESOURCE ID OF 41(refered to in above code)
                [[EditQuote]]


                which points to
                "EqitQuote" snippet
                So, this one is the redirect page.
                EditQuote snippet is fine. No change is needed.

                "quotationTplEdit" chunk, let’s delete the action url.
                <form method="post" action="">  
                    <input type="hidden" name="quoteId" value="[[+id]]" />
                    <p>Author: <input type="text" name="author" id="author" value="[[+author]]" /></p>                
                    <p>Author: <input type="text" name="topic" id="topic" value="[[+topic]]" /></p>
                    <p>Author: <input type="text" name="quote" id="quote" value="[[+quote]]" /></p>
                    <input type="submit" name="submit" id="submit" value="submit"/>
                </form>
                


                BTW,
                I believe you have a developer background since you’re asking about custom database.
                Reading http://rtfm.modx.com/display/XPDO10/Introduction+to+the+xPDO+Object+Model won’t hurt you much. tongue
                  Rico
                  Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                  MODx is great, but knowing how to use it well makes it perfect!

                  www.virtudraft.com

                  Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                  Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                  Maintainter/contributor of Babel

                  Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                  • 11055 ☆ A M B ☆
                  • 3,112 Posts
                  @BobRay,
                  I think you need to see the EditQuote snippet on your tutorial again, it looks weird to me:
                  <?php
                  /* EditQuote Snippet */
                  
                  /* Get the existing Quote */
                  $quote = $modx->(getObject('Quotation', array('id'=>$quoteId));
                  /**
                   * For anyone else reading this, $quoteId comes from the snippet's parameter: [[!EditQuote? &quoteId=`nombre`]]
                   */
                  if (isset($_POST['submit'] && $_POST['submit'] == 'MySubmitVar')) {
                     /* Form has been submitted */
                  
                      // this part is useless, and misleading
                      $fields = array(
                        'topic' => $post['topic'],
                        'quote' => $post['quote'],
                        'author' => $post['author'],
                      );
                     
                      // these parts are missing
                      $quote->set('topic', $_POST['topic']);
                      $quote->set('quote', $_POST['quote']);
                      $quote->set('author', $_POST['author']);
                      
                      if ( $quote->save()) {
                          $output = "Quote Created";
                      } else {
                          $output = "Error";
                      }
                  } else {
                      /* Not a repost, just display the form */
                  
                      /* The second argument to getChunk() tells MODx to replace
                       * the placeholders with the existing quote's values
                       */
                  
                      $output = $modx->(getChunk('quotationTpl',$quote->toArray()) );
                  }
                  $return $output;
                  
                    Rico
                    Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                    MODx is great, but knowing how to use it well makes it perfect!

                    www.virtudraft.com

                    Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                    Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                    Maintainter/contributor of Babel

                    Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
                    • 25226
                    • 29 Posts
                    Yes, I have all class information from the tutorial setup. At this point, I have no trouble at all with Creating a Brand New Record from an empty form and showing custom table results records. Which is extremely weird that the edit record is not working. I even tried using $quote = $modx->newObject() right before the $quote->save() to see if it would just make a new record. Didnt work.

                    What its starting to look like to me is that the form onSubmit function is not being triggered. Dont know why, but I have tried adding just random crap code that should have caused an error when I hit submit and it doesnt, the screen just flashes.

                    GoldSky - Did you find any errors in the code I presented before? I noticed you had me remove the "Action" call from the form and change the Edit link structure(was your preference). Other than that there was no other comments.

                    I dont understand, I am able to do this generic basic stuff everywhere else but here. I know that modx has a learning curve to it, but just interacting with a form and custom table has not been easy to do. I am a bit concerned what ill be facing with implementing more advanced table interactions.

                    Anyone have any ideas???? Help Please!

                      • 11055 ☆ A M B ☆
                      • 3,112 Posts
                      do you have another submit button from a different form (like Login or Register or Search) on the same page with the same name="submit"?

                      Because I think the problem lies in this conditional:
                      <?php //highlight
                      
                      if (isset($_POST['submit']) && ($_POST['submit'] == 'submit')) {
                       // ...
                      
                        Rico
                        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
                        MODx is great, but knowing how to use it well makes it perfect!

                        www.virtudraft.com

                        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

                        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

                        Maintainter/contributor of Babel

                        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.