We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32337
    • 28 Posts
    @AHHP I’ve done that, I don’t understand a lot of it. Basically, if I have a table in the database, which would be the appropriate event to use to add the contents of 3 custom fields and the content field?

    Following the examples provided in jot.events.php, specifically the onFirstRun and onSaveComment events, I thought that I could basically copy them to accomplish saving the custom fields to a table of my choice and then sending a confirmation email to the address provided.

    Following the example for onSaveComment() almost to the letter, I wrote something like this:
    function onSaveComment($id, $object)
    {
    
        global $modx;
        $insert = array(
    		  "firstName" => $object->cfields['firstName']
    		  "lastName" => $object->cfields['lastName']
    		  "email" => $object->cfields['email']
    		  "content" => $object->fields['content']
    	  );
          // Run the db insert query
          $modx->db->insert($insert, 'modx_example' );
    }


    Which did exactly nothing.

    I rewrote it as:
          global $modx;
          // Init our array
          $dbTable = array();
          $dbTable[firstName] = $object->cfields[firstName];
          $dbTable[lastName] = $object->cfields[lastName];
          $dbTable[email] = $object->cfields[email];
          $dbTable[content] = $object->fields[content];
          // Run the db insert query
          $modx->db->insert($dbTable, 'modx_example' );

    And tried again but nothing happened with that particular action. However when I put the same code in a number of other locations, a row was created in the table but each field was empty.

    I’d appreciate any guidance or explanation you can provide.
      • 33992 ☆ A M B ☆
      • 455 Posts
      My mistake again undecided
      Get new zip file!
        God loves me. 【ツ】


        MODX.ir (Persian Support)

        Boplo.ir/modx/ (Persian)
        • 9496
        • 113 Posts
        Sweet. I got it working. It looks like I was downloading that new version to a different directory and I kept uploading the old one. Nice whats that definition of insanity? Anyway works like a charm. I had another problem though with maxigallery auto generating tag id’s so the jotx call would only display those comments that didnt have a tag id. (Which all of them will.)

        So looking at the events.php I looked at the onbeforegetcomments function (line 454)

        I switched the where statement from:
        WHERE tagid = '$tagid' AND mode = '0' 

        to:
        WHERE mode = '0' 


        and it works. Returns all comments regardless of doc or tag id. It also doesnt affect my individual photo pages (Im using the specific tagid in the template jot call which isnt affected by this)

        So all in all nice work AHHP!
          • 33992 ☆ A M B ☆
          • 455 Posts
          Quote from: Fatknuckle at Sep 22, 2009, 04:59 PM
          I had another problem though with maxigallery auto generating tag id’s so the jotx call would only display those comments that didnt have a tag id. (Which all of them will.)
          The function gets tagid from current Jot call so it was empty because there was no &tagid or it’s value was empty.

          For Perfect feature, you could do same as docid=`*` sample code for tagid and use &tagid=`*` in your call...
            God loves me. 【ツ】


            MODX.ir (Persian Support)

            Boplo.ir/modx/ (Persian)
            • 9496
            • 113 Posts
            I thought of that too. Makes more sense but I was running out the door, so I was being kinda lazy. But you are definitely right, Ill definitely be setting up that way.
            Thanks again-
            P

            However for some reason I cant get that statement to work under the on before config I added this:

            		if($object->parameters['tagid'] == '*')
            		$GLOBALS['_tagid'] = '*';	// Add new item to use later


            And then in the onbeforegetcomments i got this:
            	if(isset($GLOBALS['_docid']) && $GLOBALS['_docid'] == '*')
            	{
            		global $modx;
            		$sql = "
            			SELECT a.* FROM " .$modx->getFullTableName("jot_content"). " AS a $tblcustom 
            			WHERE tagid = '$tagid' AND mode = '0' 
            			$where $orderby $limit
            		";
            		
            		return $sql;
            	}
            	
            }


            Then in the call it looks like this:

            [[Jot? &placeholders=`1` &output=`0` &docid=`*` &debug=`0`]]

            Im not sure the relevance of the where clause in this case. Is there any case where I would want to have a document wildcard yet a tag id? Im thinking too hard about it I spose.
              • 33992 ☆ A M B ☆
              • 455 Posts
              You added `*` to tagid but you’ve used docid in your call. Use this:
              [[Jot? &placeholders=`1` &output=`0` &tagid=`*` &debug=`0`]]
                God loves me. 【ツ】


                MODX.ir (Persian Support)

                Boplo.ir/modx/ (Persian)
                • 9496
                • 113 Posts
                While I got everything working well as far as the wildcard, now my delete comment button isnt working.

                Heres my call:

                [+jot.html.form.[+maxigallery.picture.id+]+]
                		<h2>Comments</h2>[+jot.html.comments.[+maxigallery.picture.id+]+]
                	[[Jot? &placeholders=`1` &output=`0` &tagid=`[+maxigallery.picture.id+]` &canpost=`Registered` &canmoderate=`WebAdmin,Registered` &canedit=`Registered` ]]
                 


                I thought it may be something on my comment template but just using the default template it doesnt work either. Cached unchached that doesnt seem to make a difference either. It says are you sure you want to delete this comment? I hit yes and the comment still stays there and it doesnt get deleted from the jot_content table (I checked it just to make sure)

                However the edit button works as it should...driving me batty but I appreciate all of the help-
                P

                FWIW - I switched back to the default Jot and its working fine.
                  • 9496
                  • 113 Posts
                  So basically I am figuring it has something to do with the onDeleteComment event. Heres your function that was located in the jot.db.class.inc.php file:

                  	function Delete(){
                  		global $modx;
                  		if($this->isNew) return;
                  		$id=$this->fields['id'];
                  		
                  		
                  		// onDeleteComment
                  		$return = onDeleteComment($id);
                  		if( ! is_null($return) )
                  			$modx->db->delete($this->tbl["content"],"id=$id");
                  		$this->isNew=true;
                  	}


                  Now if I replace it with the delete function from the release version it works again.

                  	function Delete(){
                  		global $modx;
                  		if($this->isNew) return;
                  		$id=$this->fields['id'];
                  		$modx->db->delete($this->tbl["content"],"id=$id");
                  		$this->isNew=true;
                  	}


                  Again my eyes are underwater here. Im not sure how it ties into everything you are trying to accomplish (Im definitely more of a front end guy that like to get his hands dirty) but Id thought id point it out.

                  UPDATE: It looks as if the problem is with this line:

                  	if( ! is_null($return) )

                  If I comment out only that line it seems to work.
                  -P
                    • 33992 ☆ A M B ☆
                    • 455 Posts
                    If you comment the IF line, the return effect of event will be disabled. You would just remove "!" in line:
                    if( is_null($return) )

                    Thank you for reporting friend, i updated attached file....
                      God loves me. 【ツ】


                      MODX.ir (Persian Support)

                      Boplo.ir/modx/ (Persian)
                      • 9496
                      • 113 Posts
                      Good stuff. Works like a charm. FYI I got the tag id wildcard working per your suggestion.
                      Thanks again-
                      P