We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8168
    • 1,118 Posts
    Quote from: BobRay at Sep 24, 2015, 11:08 PM
    What do the results look like when you submit the form? If the options all have the same name, they will come through as an array based on the 'name' in the form.

    If the page posts to itself, you can put a snippet at the top with this code:

    echo print_r($_POST['nameOfField']); It will be empty when the form loads, but it should display the user's choices on submission. If it does, I think the hook will have a reference to the user object, so this should work:

    $profile = $user->getOne('Profile');
    if ($profile) {
        $extended = $profile->get('extended');
        $variableFromForm = $hook->getValue('variableFromForm');
        $extended['somefield'] = implode(',', $variableFromForm);
        $extended->save();
    }

    Hi Bob - Some more detail on this issue has been document here on its own forum post > http://forums.modx.com/thread/98413/getting-login-register-and-updateprofile-to-accept-multiple-select-field-values#dis-post-532181

    HTML code on form is:

    <select name="workregion[]" multiple="multiple" size="5" tabindex="13">
    <option value="SouthWest">South West</option>
    <option value="London">London</option>
    </select>
    


    Output before form submission is:

    1
    


    Output on form submission (if both options are selected) is:

    Array ( [0] => SouthWest [1] => London ) 1
    


    The hook code you suggested also makes the register form fail btw - I get a white screen after submission... sorry ;( [ed. note: dubbs last edited this post 8 years, 7 months ago.]
      • 3749
      • 24,544 Posts
      Try adding this to the end of the hook:

      return true;
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 8168
        • 1,118 Posts
        Quote from: BobRay at Sep 26, 2015, 04:28 AM
        Try adding this to the end of the hook:

        return true;

        Thanks - Error log shows:

        Array
        (
            [0] => 42000
            [1] => 1064
            [2] => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `modAccess` WHERE `modAccess`.`principal` = 52' at line 1
        )
        
          • 3749
          • 24,544 Posts
          See if this does it:

          $user = $hook->getValue('register.user');
          
          $profile = $user->getOne('Profile');
          if ($profile) {
              $extended = $profile->get('extended');
              $variableFromForm = $hook->getValue('variableFromForm');
              $extended['somefield'] = implode(',', $variableFromForm);
              $extended->save();
          }
          return true;
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 8168
            • 1,118 Posts
            Quote from: BobRay at Sep 27, 2015, 06:29 AM
            See if this does it:

            $user = $hook->getValue('register.user');
            
            $profile = $user->getOne('Profile');
            if ($profile) {
                $extended = $profile->get('extended');
                $variableFromForm = $hook->getValue('variableFromForm');
                $extended['somefield'] = implode(',', $variableFromForm);
                $extended->save();
            }
            return true;

            As a prehook I still get the below outputted and no error:

            Array ( [0] => SouthWest [1] => London ) 1 


            As a posthook, the register form fails to show success, instead a white screen and I get this in the error log:

             [2015-09-27 12:03:56] (ERROR @ public_html/core/cache/includes/elements/modsnippet/64.include.cache.php : 8) PHP warning: implode(): Invalid arguments passed

              • 3749
              • 24,544 Posts
              Did you replace 'variableFromForm' in the getValue() call with the actual field name? The error means that that variable is empty or not an array.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 8168
                • 1,118 Posts
                Quote from: BobRay at Sep 28, 2015, 06:27 AM
                Did you replace 'variableFromForm' in the getValue() call with the actual field name? The error means that that variable is empty or not an array.

                Hiya, I was using the code below (the formfield is "workregion"):

                <?php
                $user = $hook->getValue('register.user');
                 
                $profile = $user->getOne('Profile');
                if ($profile) {
                    $extended = $profile->get('extended');
                    $variableFromForm = $hook->getValue('variableFromForm');
                    $extended['workregion'] = implode(',', $variableFromForm);
                    $extended->save();
                }
                return true;
                


                Also just tried the below and still get the register success page fail, even though the member is created - but the data in the workregion field is still as an array and not a comma seperated list... sad

                <?php
                $user = $hook->getValue('register.user');
                 
                $profile = $user->getOne('Profile');
                if ($profile) {
                    $extended = $profile->get('extended');
                    $variableFromForm = $hook->getValue('workregion');
                    $extended['workregion'] = implode(',', $variableFromForm);
                    $extended->save();
                }
                return true;
                
                [ed. note: dubbs last edited this post 8 years, 6 months ago.]
                  • 8168
                  • 1,118 Posts
                  Bob - I have given up on this and instead gone with just displaying a number of single option select elements, so the storing and retrieval of the values is much more simple wink Thanks for your attempts to resolve this - strange its such a hard one to get working! Sorry for those finding this post seeking a solution....