On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Which jQuery version?
    • could someone please explain this?

      The usage instructions read: With two Formit hooks the upload queue could be pre filled from Formit field value and saved into Formit field value.

      What are the TWO hooks and how would you set them?

      my issue is this... I'm creating a form that submits to the db. one of the fields is "poster image" of which I want the user to upload thus using this snippet. I need it to send the path of the image in the submit so when the db is queried it will output the path to the image...BUT what i really would like it to do is grab the userid and create/put the image in the folder created. so essentially each user would have it's own directory...

      I am snippet challenged smiley I'm learning but thus far have relied on the base properties of the snippets I'm using...
      • Quote from: Jako at Jan 01, 2014, 07:26 PM
        Which jQuery version?
        it appears that the snippet is loading the the reference to jQuery correct?
        I am not supplying a reference to it in the head tag but the output as seen in the pagesource, shows it being called as http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
        • Quote from: d1ckyh at Jan 01, 2014, 07:34 PM

          What are the TWO hooks and how would you set them?
          The Hooks are called Formit2AjaxUpload and AjaxUpload2Formit. They are working together with FormIt as hooks (http://rtfm.modx.com/extras/revo/formit/formit.hooks).

          To save/retreive the user data you could use Formit2db (http://rtfm.modx.com/extras/revo/formit2db). The hooks of that package have to work before/after the AjaxUpload hooks.

          Should work like this (untested):

          [[!Formit?
          ...
          &preHooks=`db2FormIt, Formit2AjaxUpload`
          &hooks=`AjaxUpload2Formit, FormIt2db`
          &ajaxuploadFieldname=`image`
          &ajaxuploadTarget=`images/user/[[!+modx.user.username]]/`
          &ajaxuploadUid=`image`
          &packagename=`userimages`
          &classname=`userimages`
          &tablename=`userimages`
          &where=`{userid:"[[!+modx.user.id]]"}`
          &autoPackage=`1`
          ]]


          This call should save/retrieve the images in a user folder and saves/retreives the data on MODX user id base in a custom table called modx_userimages (or whatever table prefix you use).
          • Quote from: d1ckyh at Jan 01, 2014, 07:07 PM

            only js error I see now is SyntaxError: Using //@ to indicate source map URL pragmas is deprecated. Use //# instead which is coming from jquery.min.js

            That //@ is in the http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js in the second line. Maybe the url is outdated or googleapis has a problem.
            • Quote from: Jako at Jan 01, 2014, 08:04 PM
              Quote from: d1ckyh at Jan 01, 2014, 07:34 PM

              What are the TWO hooks and how would you set them?
              The Hooks are called Formit2AjaxUpload and AjaxUpload2Formit. They are working together with FormIt as hooks (http://rtfm.modx.com/extras/revo/formit/formit.hooks).

              To save/retreive the user data you could use Formit2db (http://rtfm.modx.com/extras/revo/formit2db). The hooks of that package have to work before/after the AjaxUpload hooks.

              Should work like this (untested):

              [[!Formit?
              ...
              &preHooks=`db2FormIt, Formit2AjaxUpload`
              &hooks=`AjaxUpload2Formit, FormIt2db`
              &ajaxuploadFieldname=`image`
              &ajaxuploadTarget=`images/user/[[!+modx.user.username]]/`
              &ajaxuploadUid=`image`
              &packagename=`userimages`
              &classname=`userimages`
              &tablename=`userimages`
              &where=`{userid:"[[!+modx.user.id]]"}`
              &autoPackage=`1`
              ]]


              This call should save/retrieve the images in a user folder and saves/retreives the data on MODX user id base in a custom table called modx_userimages (or whatever table prefix you use).
              THANK YOU!
              If I'm understanding it will, on form submit, upload the image to a created folder. and if I want to set the path in an existing table with the field of posterimage, that would be &ajaxuploadFieldname=`posterimage` and I would leave out the last 2 lines (where= and autopackage=, correct? Thanks Again!
              • Those lines are for AjaxUpload:
                &ajaxuploadFieldname=`image`
                &ajaxuploadTarget=`images/user/[[!+modx.user.username]]/`
                &ajaxuploadUid=`image`


                The formfield is 'image', the folder is an existing (maybe a problem - could be solved but not in this thread) username based subfolder in 'assets/images/user/'

                And the next ones for Formit2db:
                &packagename=`userimages`
                &classname=`userimages`
                &tablename=`userimages`
                &where=`{userid:"[[!+modx.user.id]]"}`
                &autoPackage=`1`


                The table (and class-/packagename) is defined, the userid is used as where clause to look which db row has to be changed with the filename. The fieldnames in that table should have the same name as the name attribute of the according form fields.
                • Quote from: Jako at Jan 01, 2014, 08:46 PM
                  Those lines are for AjaxUpload:
                  &ajaxuploadFieldname=`image`
                  &ajaxuploadTarget=`images/user/[[!+modx.user.username]]/`
                  &ajaxuploadUid=`image`


                  The formfield is 'image', the folder is an existing (maybe a problem - could be solved but not in this thread) username based subfolder in 'assets/images/user/'

                  And the next ones for Formit2db:
                  &packagename=`userimages`
                  &classname=`userimages`
                  &tablename=`userimages`
                  &where=`{userid:"[[!+modx.user.id]]"}`
                  &autoPackage=`1`


                  The table (and class-/packagename) is defined, the userid is used as where clause to look which db row has to be changed with the filename. The fieldnames in that table should have the same name as the name attribute of the according form fields.

                  If I'm being dense I'm sorry... are you saying that ajaxuploadFieldname can be nothing other than image? and that the table field and the form field must also be image? or can these be changed to the actual fieldname in the table that I am trying to populate, i.e posterimage.

                  the reason I'm asking is because I have other fields in the table which are image paths but this form is not affecting those fields as they are joined to other tables.

                  My other question is if I used db2formit and the user wants to change the image previously uploaded if I use ajaxupload with the same parameters will it append the field in the db
                  • Then you have to change the parameter ajaxuploadFieldname to i.e. posterimage.

                    Already uploaded images are managed by AjaxUpload with that call above (a comma separated list of file names is saved in the DB).
                    • Very Grateful for all of your help! Thank You...