PDA

View Full Version : Problem with pagination URL


TheAdminMarket
10-17-2014, 04:08 PM
Hello all,

Does anybody know what appears in the URL when one parameter is array? eg:
&genders=Array&roles=Array
is correct?

Actually it must be correct as the pagination works just fine (I mean navigating between the pages), but I can't get the values for another action that I want.

Testing the 1st page with:

if (is_array($genders))
{
echo "1";
print_r($genders);
}

I'm getting: 1Array ( [0] => 1 [1] => 2 ) which is correct. But moving to any other page I'm getting: 1Array ( ) . Empty array.

The most important parts of the code before are:

$vbulletin->input->clean_array_gpc('r', array(
'homeform' => TYPE_INT,
'genders' => TYPE_ARRAY_INT,
'roles' => TYPE_ARRAY_INT,
....
));
$genders = $vbulletin->GPC['genders'];
$roles = $vbulletin->GPC['roles'];
// Below I've the code for counting the amount of rows etc etc.
..........
// Storing the values to pass them as parameters
$postvalues .= "&genders=".$genders;
$postvalues .= "&roles=".$roles;
// Finally building the page navigation
$pagenav = construct_page_nav($pagenumber, $perpage, $records, 'dating.php?' . $vbulletin->session->vars['sessionurl'] . 'do=searchresults'.$postvalues.'');


I also tried in postvalues:

$postvalues .= "&genders=".implode(',',$genders);

This changed the URL to &genders=1,2 but still can't get the values. Don't know if in this case I must use: TYPE_STR instead of TYPE_ARRAY_INT

Any idea is welcome :)

Thank you

Lynne
10-17-2014, 05:48 PM
Since you are getting passed a single value (ie. initially it is genders=1 or genders=2, right?), then it is simply a string or integer at that point - it isn't an array that is getting passed via the URL.

TheAdminMarket
10-17-2014, 06:13 PM
Since you are getting passed a single value (ie. initially it is genders=1 or genders=2, right?), then it is simply a string or integer at that point - it isn't an array that is getting passed via the URL.

First of all thank you for your prompt attention. You're always here to help people. Really appreciated.

No, I'm passimg array of values from the initial form to genders[]. The first page works just fine. I'm using these array values to preselect the form that exists in the searchresults page.

The problem starts to appear when I'm navigating to any other page using the pagination (always on the same php file/page). The navigation works, but I'm loosing the values of the variables.

Maybe the solution can be childish. Is that $postvalues at the end of:

$pagenav = construct_page_nav($pagenumber, $perpage, $records, 'dating.php?' . $vbulletin->session->vars['sessionurl'] . 'do=searchresults'.$postvalues.'');

something needing for constructing the pagination, or not? If not then I believe that I can find a solution.

Thank you again

Lynne
10-17-2014, 06:19 PM
You're passing an actual array? What does this URL look like initially - &genders=1,2&roles=1,2 ?

TheAdminMarket
10-17-2014, 06:40 PM
You're passing an actual array? What does this URL look like initially - &genders=1,2&roles=1,2 ?

Yes, the URL appears like that if I use the implode function like:

$postvalues .= "&genders=".implode(',',$genders);
$postvalues .= "&roles=".implode(',',$roles);


If I use:

$postvalues .= "&genders=".$genders;
$postvalues .= "&roles=".$roles;

then the URL looks like: &gender=Array&roles=Array

Lynne
10-17-2014, 08:38 PM
I notice you aren't separating the post variables with "&" which would need to be done after do=searchresults (the session variable has one at the end). So, you need to fix that. But, I'd also suggest looking at the construct_page_nav function (in functions.php) because I'm not totally sure if it is set up to handle and array being passed.

TheAdminMarket
10-18-2014, 06:24 AM
Finally I was able to solve the problem and I'm posting the solution here just in case someone else finds the same problem when passing arrays in URL. The trick is to use serialize/unserialize.

So in the passing to the URL you use:

$url = urlencode(serialize($array))

and to restore the variable you use

$var = unserialize(urldecode($_GET['array']))


Thank you very much Lynne.

Lynne
10-18-2014, 04:55 PM
I'm glad you figured it out and thanks for posting the solution. :)