<![CDATA[ User-selectable Limit - My Forums]]> https://forums.modx.com/thread/?thread=103664 <![CDATA[User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557626
Using pdoResources / pdoPage (and pagination controls) to show a listing of resources is there a way to allow a visitor to select the number of results to display using a picker?

Right now I'm using the &limit=`10` property but it's static, I would prefer the value be set from the front-end. For example, the default value might be 10 with additional picker options of 15, 20, Show All. And changing the value would automatically refresh the page.]]>
todd.b Mar 24, 2018, 09:22 PM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557626
<![CDATA[Re: User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557696
<?php
$value = 10;

if (array_key_exists('results_to_show', $_POST) && is_numeric($_POST['results_to_show'])) {
  $value = (int)$_POST['results_to_show'];
}

// make it available as [[!+results_to_show]]
$this->setPlaceholder('results_to_show', $value);
// OR
// if you want to use the snippet inside the call directly
return $value;

]]>
markh Mar 28, 2018, 10:10 AM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557696
<![CDATA[Re: User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557670
Thanks BobRay and Mark H., I'll take another look at it when I have more time.]]>
todd.b Mar 27, 2018, 07:50 AM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557670
<![CDATA[Re: User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557665 Looking at Mark's example above is this all that's required?
($_POST['results_to_show'])

Yes, but you need an input field with name="results_to_show" in order for that value to end up in the $_POST array.]]>
BobRay Mar 27, 2018, 04:43 AM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557665
<![CDATA[Re: User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557663
I seem to be having trouble getting the stripped-down version Mark suggested to work.

I created a basic form:
<form method="post">
    <select>
        <option value="10">10</option>
        <option value="20">20</option>
        <option value="0">View All</option>
    </select>
</form>

I set &limit=`[[!++results_to_show]]` and created a snippet named "results_to_show" then added the code you provided but nothing happens. Since I don't need to store anything I'm unsure how to modify the code you provided.

Looking at Mark's example above is this all that's required?
($_POST['results_to_show'])
]]>
todd.b Mar 26, 2018, 06:38 PM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557663
<![CDATA[Re: User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557660 BobRay Mar 26, 2018, 06:17 PM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557660 <![CDATA[Re: User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557639 markh Mar 26, 2018, 06:11 AM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557639 <![CDATA[Re: User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557637 todd.b Mar 26, 2018, 03:37 AM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557637 <![CDATA[Re: User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557629 todd.b Mar 25, 2018, 04:02 AM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557629 <![CDATA[Re: User-selectable Limit]]> https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557627
Then use this in the pdoResources call:

&limit=`[[!++results_to_show]]`


The code to save the value would look something like this:

if (isset($_POST['results_to_show']) && isset($_POST['submitValue'])) {
    $userId = $modx->user->get('id');
    $key = 'results_to_show';
    $value = $_POST['results_to_show'];

    $setting = $modx->getObject('modUserSetting', array('user' => $userId, 'key' => $key));

    if (! $setting) {
        $setting = $modx->newObject('modUserSetting');
        $setting->set('user', $userId);
        $setting->set('key', 'results_to_show');
    }

    $setting->set('value', $value);
    $setting->save();
}
return;



The value could also be stored in an extended field of the user profile, or in an unused user or profile field, but that would require using another snippet or tag to retrieve the value.
]]>
BobRay Mar 24, 2018, 10:19 PM https://forums.modx.com/thread/103664/user-selectable-limit#dis-post-557627