Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

modifying tep_get_all_get_params()


Antonio Garcia

Recommended Posts

I try to modify the tep_get_all_get_params() function to get the values of the $_GET variables when are 'arrays' insead 'single' values.

 

(For example, when you submit a form with a select field with a 'multiple' option you get a array insead a single value).

 

As you know it work well if you want to reproduce a urls like:

 

XXX.php?action=delete&id=22

 

But if I have some like this:

 

XXX.php?action=delete&id%5B%5D=22&id%5B%5D=23

 

This function don't work at all because the value of 'id' is an array with values id[0]=22 and id[1]=23

 

When I try to use in a new script that uses:

 

tep_href_link(FILENAME_XXX, tep_get_all_get_params())

 

to jump to the same file but with the $HTTP_GET_VARS (some of them Arrays) don't work.

 

 

I try with this:

////

// Return all HTTP GET variables, except those passed as a parameter

  function tep_get_all_get_params($exclude_array = '') {

    global $HTTP_GET_VARS;

 

    if (!is_array($exclude_array)) $exclude_array = array();

 

    $get_url = '';

    if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {

      reset($HTTP_GET_VARS);

      while (list($key, $value) = each($HTTP_GET_VARS)) {

        if ( (strlen($value) > 0) && ($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {

          // modification

    if (is_array($value)) {

    while (list($key, $value2) = each($value)) {

    $get_url .= $key . '=' . rawurlencode(stripslashes($value2)) . '&';

  }

 

    } else {

  // modification end

    $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';

    }

        }

      }

    }

 

    return $get_url;

  }

 

/////////////////////////////

 

But it don't work.

 

Any ideas?

 

All the best.

 

Antonio

Link to comment
Share on other sites

I think this will work for ya.

 

////
// Return all HTTP GET variables, except those passed as a parameter
 function tep_get_all_get_params($exclude_array = '') {
   global $HTTP_GET_VARS;

   if (!is_array($exclude_array)) $exclude_array = array();

   $get_url = '';
   if (is_array($HTTP_GET_VARS) && (sizeof($HTTP_GET_VARS) > 0)) {
     reset($HTTP_GET_VARS);
     while (list($key, $value) = each($HTTP_GET_VARS)) {
       if (is_array($value)) {
         while (list($key2, $value2) = each($value)) {
           if ( (strlen($value2) > 0) ) {
             $get_url .= $key . rawurlencode('[' . $key2 . ']') . '=' . rawurlencode(stripslashes($value2)) . '&';
           }
         }
       } else {
         if ( (strlen($value) > 0) && ($key != tep_session_name()) && ($key != 'error') && (!in_array($key, $exclude_array)) && ($key != 'x') && ($key != 'y') ) {
           $get_url .= $key . '=' . rawurlencode(stripslashes($value)) . '&';
         }
       }
     }
   }

   return $get_url;
 }

/////////////////////////////

Link to comment
Share on other sites

A function was recently added to CVS to take care of such situations, and can be found at the bottom of the following page:

 

http://cvs.oscommerce.com/viewcvs.cgi/admi...=1.167&r2=1.168

 

The osc_sanitize_multidimensional_array() function also takes care of multidimensional arrays.

 

Hope that helps!

:heart:, osCommerce

Link to comment
Share on other sites

Dear Dave:

 

Thanks for the corrected script!

 

It work well!

 

I really are unable to find the right solution until I found at

Using HTML forms with PHP. Access single and multiple form values

a good tutorial about this 'problem' and also there are a script that solves this, but I put your code into our general.php because is 'more osCommerce coding' that the other... ;)

 

Thanks again

 

Dear Harald:

 

Thanks for the info you supply.

 

I understand that this info are not to solve my problem but to inform to all thas this 'problem' are now covered by new code (that I are unable to use it because I use a MS2.2....).

 

All the best.

 

Antonio

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...