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
    Hi, someone out there must know how to do this... can't believe I am the first one to ask it!

    How can I get the Login Extra both on the Register and also UpdateProfile element accept a multiple select form field - e.g.

    <select name="workregion[]" multiple="multiple" size="5" tabindex="13">
       <option value="SouthWest" [[!+reg.workregion:is=`SouthWest`:then=`selected`]]>SouthWest</option>
       <option value="London" [[!+reg.workregion:is=`London`:then=`selected`]]>London</option>
    </select>
    


    So, I want the user to be able to select as many of the 'select options' as they want, and when they hit the register/update button on the form, I want the details of this selection to be passed to the 'workregion' extended user field I have for the member.

    I then also want the way the data is stored in the 'workregion' extended user field to be interpreted correctly when the user views the update profile form - e.g. so that their original selections are highlighted in the select list that is rendered for the 'workregion' form field....

    Is this possible??? Surely it must be??? I have tried loads of things but nothing seems to work... I appear to have an array of results which when viewed in the MODX USERS manager area displays as:

    workregion
    0 - SouthWest
    1 - London

    So it looks like the data is being subset by MODx when it receives it...

    I also need this data stored in the workregion field to be searchable within the MODx manager - not sure if this affects how it is extracted and stored from the 2 forms...

    I am happy to use a group of checkboxes if its easier that way... but I can't get that to work either!

    Any ideas???


    Cheers,

    dubbs.
      • 8168
      • 1,118 Posts
      Anyone ideas on this one??? Surely its possible? Afraid I just don't know enough PHP to work it out!
        • 3749
        • 24,544 Posts
        Are you seeing any data at all in the workregion extended field when you edit a user, and if so what?

        For one thing, your method of setting their current values with an output modifier can't work. workregion is either an array, or a delimited list of locations, so it's never going to equal London or SouthWest.

        I think you're looking at a custom preHook and postHook for UpdateProfile and a custom postHook for Register.

        Try this in a Register postHook and see what it puts in the error log:

        $wr = $hook->getValue('workingregion');
        $msg = 'Working Region: ' . print_r($wr, true);
        $modx->log(modX::LOG_LEVEL_ERROR, $msg);
        return true;
        




        [ed. note: BobRay last edited this post 8 years, 6 months ago.]
          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, 05:32 AM
          Are you seeing any data at all in the workregion extended field when you edit a user, and if so what?

          For one thing, your method of setting their current values with an output modifier can't work. workregion is either an array, or a delimited list of locations, so it's never going to equal London or SouthWest.

          I think you're looking at a custom preHook and postHook for UpdateProfile and a custom postHook for Register.

          Try this in a Register postHook and see what it puts in the error log:

          $msg = 'Working Region: ' . printr($hook->getValue('workingregion'), true);
          $modx->log(modX::LOG_LEVEL_ERROR, $msg);
          return true;
          





          Hi Bob - did that, got a white screen on register submission - but the submission did work as I can see the new member in the users section of the Manager. Error log as below:

           [2015-09-26 22:07:26] (ERROR @ /index.php) Could not get table class for class: modAccess
          [2015-09-26 22:07:26] (ERROR @ /index.php) Could not get table name for class: modAccess
          [2015-09-26 22:07:26] (ERROR @ /index.php) Error 42000 executing statement: 
          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
          )
          


          Something not right somewhere! Any thoughts?
            • 3749
            • 24,544 Posts
            My bad -- typo in the code. Try the corrected version above.
              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
              Thanks - still get a white screen after form submission, now nothing in the error log... Also register form fails now
                • 8168
                • 1,118 Posts
                Hi bob (and others! wink),

                Lets go back to basics here...

                What I need is an element of the register form to allow the member to select from a range of options that match their criteria. So the question is: Where are you looking for work - the answers will be regions of the UK, so London, South West, South East, Scotland, Wales etc... I need the user to be able to select yes to as many of these as relevant to them. I then need that data to be stored to the extended user field(s), which then when someone reviews the member (user) data - the options they said yes to are displayed, so if the user selected London and Scotland on the register form, when they view their profile it should say on the "Where are you looking for work" field - "London and Scotland". I had thought using a multiple select element was best - but perhaps its not the way to do this....

                I was hoping to store all the selected options into a single field, which would read "London, Scotland" for example...

                I currently have the data being stored in an array which in the MODx user field looks like:

                workregion
                > 0 Scotland
                > 1 London

                So, this is working, e.g. showing the selected options in an array (as I understand it...).

                What currently is not working, is when I try and call the [[+workregion]] in a view profile page - it displays nothing... How can I get the data back from that array to be visible either in a select list, or just as a list of text elements to say: Scotland, London - I was thinking that I needed to flatten the array to a comma separated list to make the return display of this info easier.. maybe I am wrong... Also need to consider that the member can edit their profile and so, additionally change these options at any time....



                Any thoughts?

                cheers,


                dubbs. [ed. note: dubbs last edited this post 8 years, 6 months ago.]
                  • 3749
                  • 24,544 Posts
                  This might be a perfect case for ClassExender, though you could certainly roll your own system. ClassExtender would be especially helpful if you're going to be searching based on the locations.

                  The implode() function will turn that array into a comma-separated list.

                  $list = implode(',', $workregion);


                  I think I've suggested postHook code to store it in the extended field in the other thread.

                  To get it back, all you should need is to put the Profile snippet at the top of the page with the &useExtended=`1` property (or ClassExtender's snippet for setting user placeholders). Then your placeholder should work to produce the comma-separated list.

                    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:34 AM
                    This might be a perfect case for ClassExender, though you could certainly roll your own system. ClassExtender would be especially helpful if you're going to be searching based on the locations.

                    The implode() function will turn that array into a comma-separated list.

                    $list = implode(',', $workregion);


                    I think I've suggested postHook code to store it in the extended field in the other thread.

                    To get it back, all you should need is to put the Profile snippet at the top of the page with the &useExtended=`1` property (or ClassExtender's snippet for setting user placeholders). Then your placeholder should work to produce the comma-separated list.


                    OK thanks, where do I add the
                    $list = implode(',', $workregion);
                    though?
                      • 8168
                      • 1,118 Posts
                      Quote from: dubbs at Sep 28, 2015, 10:28 AM
                      Quote from: BobRay at Sep 28, 2015, 06:34 AM
                      This might be a perfect case for ClassExender, though you could certainly roll your own system. ClassExtender would be especially helpful if you're going to be searching based on the locations.

                      The implode() function will turn that array into a comma-separated list.

                      $list = implode(',', $workregion);


                      I think I've suggested postHook code to store it in the extended field in the other thread.

                      To get it back, all you should need is to put the Profile snippet at the top of the page with the &useExtended=`1` property (or ClassExtender's snippet for setting user placeholders). Then your placeholder should work to produce the comma-separated list.


                      OK thanks, where do I add the
                      $list = implode(',', $workregion);
                      though?

                      Also - Afraid, the Profile snippet just displays nothing when I try and display the contents of the workregion field... Something not right here somewhere!