Need Submitting Array in Form in the index.php - getting error because of rawurlencode()

Open to all! Ask other shopowners for help.
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Need Submitting Array in Form in the index.php - getting error because of rawurlencode()

Post by ecartz »

I added this to 1.0.8.17.

But what I meant was that if I make the modification in Href described at viewtopic.php?p=8485#p8485 as far as I can tell, everything works. I add GET parameters to the URL so that it looks like specials.php?manufacturers_filter_id_arr[]=1494&manufacturers_filter_id_arr[]=1492 and the sort URLs look like specials.php?manufacturers_filter_id_arr[0]=1494&manufacturers_filter_id_arr[1]=1492&sort=2a


Join The Code Co-op to get access to your library in the Code Co-op Forum
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: Need Submitting Array in Form in the index.php - getting error because of rawurlencode()

Post by loop »

hmm that's strange.

i have the in href.php

Code: Select all

$parameters = implode('&', array_map(function ($k, $v) {
       // return "$k=" . rawurlencode($v); PB Addon
       return is_array($v) ? $this->build_subquery($v, $k) : "$k=" . rawurlencode($v);
      }, array_keys($this->parameters), $this->parameters));
      
      and
      
      public function build_subquery(array $parameters, string $prefix) {
      return implode('&', array_map(function ($k, $v) use ($prefix) {
        $k = "{$prefix}[{$k}]";
        return is_array($v) ? $this->build_subquery($v, $k) : "$k=" . rawurlencode($v);
      }, array_keys($parameters), $parameters));
    }
      
but the sort header in split_page_results.php is:

Code: Select all

public static function create_sort_heading($sortby, $colnum, $heading, $class = 'dropdown-item') {
      if (!$sortby) {
        return $heading;
      }

      $link = $GLOBALS['Linker']->build()->retain_query_except(['info', 'page']);
      $link->set_parameter('sort', $colnum . ($sortby == $colnum . 'a' ? 'd' : 'a'));

      $selected = substr($sortby, 0, -1) == $colnum;
      $ascending = substr($sortby, -1) === 'a';
      $title = sprintf(($selected && $ascending) ? TEXT_DESCENDINGLY : TEXT_ASCENDINGLY, $heading);
      $text = sprintf(($selected ? ($ascending ? LISTING_SORT_DOWN : LISTING_SORT_UP) : LISTING_SORT_UNSELECTED), $heading);

      return '<a href="' . $link. '" title="' . Text::output($title) . '" class="' . $class . '">' . $text . '</a>';
    }

  }
so i think the function we change are not used in this case, as

Code: Select all

    public function retain_query_except(array $excludes = []) {
      $excludes = array_merge($excludes, ['x', 'y', 'error', session_name()]);
      $this->parameters += array_diff_key(array_filter($_GET, function ($k) {
        return rawurlencode($k) === $k;
      }, ARRAY_FILTER_USE_KEY), array_flip($excludes));
      return $this;
    }

if i change the function to this:

Code: Select all

public function retain_query_except(array $excludes = []) {
      $excludes = array_merge($excludes, ['x', 'y', 'error', session_name()]);
      $this->parameters += array_diff_key(array_filter($_GET, function ($k) {
        echo $k."<br>";
        return rawurlencode($k) === $k;
      }, ARRAY_FILTER_USE_KEY), array_flip($excludes));
      echo "<br>";
      return $this;
    }
i get this output:

Code: Select all

keywords_filter_id_arr
manufacturers_filter_id_arr
price_range
B22_ALLTBILDSCHIRMDIAGONALE
group_space
count_selected_products
count_total_categories_products
cPath
sort
current_category_id
action
jquery_action
but the links ($this) is:

Code: Select all

https://xxx/product_info.php?sort=1a&jquery_action=show_products&group_space='B22_FILTER'¤t_category_id=22&count_total_categories_products=538&count_selected_products=538&action=super_filter
so that means, that the function retain_query_except() does not handle the array and filter it out.....

i'm really out of ideas :(
i tried it only on the index.php page (as i do not have specials.php) maybe i change something in my script that it works on your case and on my not, but i don't get it as i follow the script and the retain_query_except does not "start" the the real_link which use the function you suggested...
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Need Submitting Array in Form in the index.php - getting error because of rawurlencode()

Post by ecartz »

loop wrote: Sun Jul 17, 2022 8:23 pm the retain_query_except does not "start" the the real_link which use the function you suggested...
Of course it doesn't. The retain_query_except runs during the setup of the URL. The real_link doesn't run until the Href is converted into a string.

My point is that retain_query_except doesn't check anything with the values. It just filters out those keys that don't stay the same when rawurlencoded. It doesn't care what type the values are. It only looks at keys. I don't think that you are experiencing a retain_query_except problem. I think your issue lies somewhere else.
loop wrote: Sun Jul 17, 2022 8:23 pmgroup_space='B22_FILTER'¤t_category_id=22
This looks more like something is eating a portion of the URL/query string or the parameters array.

I'm not even convinced that this is happening in PHP. That might be a Javascript issue. But PHP or Javascript, I don't believe that this is a core issue. This seems to be one of the things that you added.

You might get more insight if you change your debugging code from

Code: Select all

      echo "<br>";
to

Code: Select all

      echo "$this<br>";
or

Code: Select all

      echo $this->real_link() . "<br>";
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: Need Submitting Array in Form in the index.php - getting error because of rawurlencode()

Post by loop »

i changed it now to:

Code: Select all

echo $this."<br>";
echo $this->real_link() . "<br>";
it's verry strange, if i go to:

Code: Select all

https://xxx/index.php?count_selected_products=10&cPath=864_22&sort=1a&current_category_id=22
and output is:

Code: Select all

https://xxx/product_info.php?sort=1a¤t_category_id=22&count_selected_products=10
https://xxx/product_info.php?count_selected_products=10&cPath=864_22&sort=1a&current_category_id=22
count_selected_products
so something makes the parameter "current_category_id" into ¤t_category_id in in "$this" and in the "real_link()" it works as it should. do you have a idea?

and if i have arrays in the link the "real_link" output is correct, but the $this output filters it...

one "fun" fact:
if i change the name of the parameter current_category_id to kurrent_category_id i don't have any problems and no strange sign, so something is triggered with the name "current"

Code: Select all

https://xxx/index.php?count_selected_products=10&cPath=864_22&sort=1a&kurrent_category_id=22
but if i make it with "kurrent_category_id " and i have no strange sign, the retain_query_except still filters out the array parameter, so the "strange" charactere does not change this behavior
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Need Submitting Array in Form in the index.php - getting error because of rawurlencode()

Post by ecartz »

loop wrote: Mon Jul 18, 2022 7:28 am and if i have arrays in the link the "real_link" output is correct, but the $this output filters it...

one "fun" fact:
if i change the name of the parameter current_category_id to kurrent_category_id i don't have any problems and no strange sign, so something is triggered with the name "current"

Code: Select all

https://xxx/index.php?count_selected_products=10&cPath=864_22&sort=1a&kurrent_category_id=22
but if i make it with "kurrent_category_id " and i have no strange sign, the retain_query_except still filters out the array parameter, so the "strange" charactere does not change this behavior
The retain_query_except is not filtering array parameters. Because the real_link output is correct. And real_link runs after retain_query_except. You have a hook on hrefLink that is changing the results. Look at that hook. Because the only difference between "$this" and ->real_link() is that "$this" calls the hrefLink hook (which would normally then call ->real_link()).
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: Need Submitting Array in Form in the index.php - getting error because of rawurlencode()

Post by loop »

hi eCartz
i have the module installed from Raiwa (name_based_urls.php pro version)
i deactivated it and the array is here! you were right (as always) so the module from raiwa does filter that :( and as i'm probably the only one who has array, he won't change the module....

i figured it out, maybe you can have a look on it:
on include/system/override/name_based_urls.php
the function function parse_parameters($page, $params, &$separator) {

i changed / added the "is_array" part

Code: Select all

      if(is_array($value)){
        foreach ($value as $subparam => $subvalue){
          if(is_array($subvalue)){
            foreach ($subvalue as $subparam2 => $subvalue2){
              $new_param = "{$param}[{$subparam}][{$subparam2}]";
              if( isset($subvalue2) ) $container[$new_param] = rawurlencode($subvalue2);
            }
          }else{
            $new_param = "{$param}[{$subparam}]";
            if( isset($subvalue) ) $container[$new_param] = rawurlencode($subvalue);
          }
        }
      }else{
it seems to work for 1 array and multidimensional also, but i don't know if thats the nice way or if a subquery function as you did would be better....
:

Code: Select all

  public function build_subquery(array $parameters, string $prefix) {
    return implode('&', array_map(function ($k, $v) use ($prefix) {
      $k = "{$prefix}[{$k}]";
      return is_array($v) ? $this->build_subquery($v, $k) : "$k=" . rawurlencode($v);
    }, array_keys($parameters), $parameters));
  }
but not to create the url as the function does, it should probably add it to the $container so that the function from raiwa creates the url afterwards normal....
thank you eCartz!


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply