We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1570
    • 38 Posts
    Hi,

    can anyone tell me how to specify a username in a jot post. The site im building has a custom user account system, but i would also like to use jot in it.

    I would like to be able to pass the username of the user into the jot call and have jot save that username as the username of the person who posted the comment, instead of it picking up the modx admin username.

      • 1122
      • 209 Posts
      Integrating Jot with a custom user system might be done as follows:

      1) tell Jot to use explicit field for username
      [[Jot? ... &customfields=`name` ...]]

      2) do some changes in Jot’s form by inserting hidden field to keep username
      <input type="hidden" name="name" value="[[get_user_name]]" ... />

      3) code "get_user_name" snippet -- its implementation entirely depends on technical details of your custom user system, anyway it should be something like
      if (<user-logged-into-custom-system>) {
        return <logged-user-name>;
      } else {
        return <anonymous-name>;
      }
      

      And the most important, the above is merely an outline, not a complete solution.
      • Make sure the "name" attribute of the field matches the custom field in Jot’s custom fields table; if it’s "custom_login_name" in the database table, then the form field name has to also be "custom_login_name". And when using it in a placeholder, don’t forget to add the .custom. part to it;
        Custom fields

        The custom fields you specify with &customfields will have to be added to your form chunk manually. The default templates holds an example of how a guest form looks (added fields here are: name and email)

        NOTE: Be sure to prefix custom. to custom field. ie. [+comment.custom.customfieldname.url+]
        [edit]
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 1570
          • 38 Posts
          Thanks for the reply,

          Im using the title field in jot to store the username as titles aren’t required in the comments section of the site, so i have this now:

          <input name="title" type="hidden" value="[+form.field.title:esc+]" id="title[+jot.id+]" />


          and in the jot call

          &title=`'.$username.'`


          It works fine However.....


          I dnt want to sound like a pain in the *** but this is begging to be hacked, ppl can replace the value in the hidden field easily and post comments pretending to be someone else.

          Is it possible for me to pass a user id to Jot via the jot call without havingto put the value in a hidden field and have Jot add it to the DB along with the comment. That would tie the comment to a user then i can use PHx on the comments output in Jot to pull the username.