We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25308
    • 46 Posts
    Revo 2.07
    windows server w/ Apache

    Hi all,

    I am using the Login package for user registration and profiles. I am also using Formit to send requests and communications to me from the site. I would like to pre-populate some of the Formit fields with the information that had been collected from a logged in user’s profile. I don’t want the act of filling out their name and contact info to become repetitive for them.

    Is there a current method of doing this? I didn’t find this question in any threads on the forum so I’m wondering if its something simple that I’ve just overlooked.

    Any help or resource you could point me to would be greatly appreciated. Thanks in advance for your time.
      • 21122
      • 153 Posts
      You can output user details in the front-end using the following:

      [[+modx.user.id]] - Prints the ID
      [[+modx.user.username]] - Prints the username
      etc.

      There is some more information in the Docs at http://rtfm.modx.com/display/revolution20/Users#Users-GrabbingtheUserviatheAPI

      Hope that helps.
        • 25308
        • 46 Posts
        HI I’m still wrestling with this issue. I had to take some time off to take care of some urgent items but I’m back on the trail again.

        My issue lies with populating the Formit fields with the user info from their profile.I’ve tried a variety of methods with little luck. I found this link in the Formit API documentation:

        http://rtfm.modx.com/display/ADDON/FormIt.Hooks#FormIt.Hooks-AccessingtheFormItfieldsintheHook



        I’m not sure that I understand what its telling me to do. Is there anyone that has experience with pre-filling out Formit feilds? I’ve exhausted the limits of my knowledge on this. undecided
          • 25308
          • 46 Posts
          I’ve read the "Using pre-hooks" section of the MODx documentation and it illuminates how you can pre-fill the fields with a specific input such as

          <?php
          $hook->setValue('name','John Doe');
          $hook->setValue('email','[email protected]');
          return true;


          But I want the name (ect) dependent on the specific user logged in referencing their profile. Is it possible to use
          &preHooks=`[[!profile]]` and a value="[[+name]][[!+fi.dname]]" 
          in the formit field?

          Just brainstorming,...
            • 25308
            • 46 Posts
            Quote from: neilp123 at Jul 07, 2011, 10:13 AM

            You can output user details in the front-end using the following:

            [[+modx.user.id]] - Prints the ID
            [[+modx.user.username]] - Prints the username
            etc.

            There is some more information in the Docs at http://rtfm.modx.com/display/revolution20/Users#Users-GrabbingtheUserviatheAPI

            Hope that helps.

            Hi appreciate the help with this. I took some time to try and figure it out but with little luck. I tried making a value="[[+modx.user.username]][[!+fi.dname]]" but when I viewed the page it still showed the form field as blank. Also tried a variety of different methods with the same result.

            For some reason the API grab isn’t working within the Formit formula...
            any thoughts?
              • 25308
              • 46 Posts
              ok so last night I also tried using the [[!profile]] call as a prehook
              &preHooks=`[[!profile]]`


              Then adding the appropriate calls in the value fields like:
              <label for="dname"><strong class="red">*</strong>Contact Name:
                      <span class="error">[[!+fi.error.dname]]</span></label><br />
              	<input id="dname" name="dname" type="text" value="[[+fullname]] [[!+fi.dname]]" />


              This did actually populate the fields but would not validate the form. It also kept asking me to fill in the email field even though it did populate and was not mentioned in the "&validate=" call. odd. I’m really at a loss...

              any suggestions? anyone?
                • 28215
                • 4,149 Posts
                Not sure why you’re not just using the UpdateProfile snippet in the Login Extra...but...

                Use this prehook:

                <?php
                if (!$modx->user->hasSessionContext($modx->context->get('key'))) return false;
                
                $placeholders = $modx->user->toArray();
                $profile = $modx->user->getOne('Profile');
                if ($profile) {
                   $placeholders = array_merge($profile->toArray(),$placeholders);
                   $extended = $profile->get('extended');
                   $placeholders = array_merge($extended,$placeholders);
                }
                $hook->setValues($placeholders);
                return true;
                


                That should work.
                  shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                  • 25308
                  • 46 Posts
                  Quote from: splittingred at Aug 03, 2011, 02:53 PM

                  Not sure why you’re not just using the UpdateProfile snippet in the Login Extra...but...

                  Use this prehook:

                  <?php
                  if (!$modx->user->hasSessionContext($modx->context->get('key'))) return false;
                  
                  $placeholders = $modx->user->toArray();
                  $profile = $modx->user->getOne('Profile');
                  if ($profile) {
                     $placeholders = array_merge($profile->toArray(),$placeholders);
                     $extended = $profile->get('extended');
                     $placeholders = array_merge($extended,$placeholders);
                  }
                  $hook->setValues($placeholders);
                  return true;
                  


                  That should work.

                  Thank you splittingred! I’ll try this next.

                  Sorry I should have clarified,.. This is to populate my formit forms with user profile information. There are multiple formit forms on the site and I wanted to make it easier on the user by pre-filling as many of the fields as possible that were collected during the user registration using the login package. I have forms like "Contact us" and "Write a review" that are sent to my email address and not stored in a database.

                  Thanks for looking into this,.. much appreciated ; )
                    • 25308
                    • 46 Posts
                    ok so I finally figured this out. After taking to heart the "You can make almost anything a prehook" statement from the Formit instructions on the wiki: http://rtfm.modx.com/display/ADDON/FormIt.Hooks#FormIt.Hooks-AccessingtheFormItfieldsintheHook I ended up with a working solution.

                    This is helpful if you have multiple formit forms on your site such as "Contact" and "write a review" (ect) and want to populate them with the information from a registered users profile information. Honestly its just nice for the user experience to automatically fill out name, email and what ever else is applicable for them. Cuts out repetition for them,.. I know I appreciate it.

                    Really this is database 101,... I just had no idea how to do it within the confines of MODx. As flexible as it is I have no Idea about the API. YET.... ; ) Luckily the crew that put MODx together made it this flexible. (THANKS!!)

                    My working solution is this. (I’m assuming you have the login package and understand Formit and have them already installed)
                    _____________________________________________________________________________________________________________________________-

                    1. Start off by Calling the profile package in a prehook.
                    &preHooks=`[[!profile]]`


                    2. Create your Formit form as usual. The trick here is to make sure that you don’t name any of these form labels, error call, input id, name or values calls the same as anything collected in your Login registration. In the "value" area of the form field add in the appropriate profile call that you want to populate this field.

                    Below I have the example of collecting the "name" on my form. I simply named the formit field and its respective parts "dname".
                    <label for="dname"><strong class="red">*</strong>Contact Name:
                            <span class="error">[[!+fi.error.dname]]</span></label><br />
                    	<input id="dname" name="dname" type="text" value="[[+fullname]] [[!+fi.dname]]" />
                    


                    3. When you create the email Template to collect the data make sure you reference the Formit fields NOT the original Login registration names. Such as:

                    name: [[+dname]]


                    That’s it,... I’ve run it 30xs already with no problems. The user info is populated and comes over with the additional info in my emails. I know it’s a very specific need but I’m sure someone else out there will need it at some point. Good luck and I hope this helps someone else. grin grin grin
                      • 6146
                      • 48 Posts
                      Thanks for taking the time to write up your solution Robert. It was a big help.

                      I was looking for a way to do the same thing for the Simplecart checkout - which also uses FormIt.

                      Cheers!