Antonio Garcia Posted September 14, 2004 Share Posted September 14, 2004 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 More sharing options...
user99999999 Posted September 15, 2004 Share Posted September 15, 2004 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 More sharing options...
Harald Ponce de Leon Posted September 15, 2004 Share Posted September 15, 2004 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! , osCommerce Link to comment Share on other sites More sharing options...
Antonio Garcia Posted September 15, 2004 Author Share Posted September 15, 2004 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 More sharing options...
user99999999 Posted September 16, 2004 Share Posted September 16, 2004 hI hpdl, Thats a nice function but what about $exclude_array and urlencoding? Link to comment Share on other sites More sharing options...
user99999999 Posted September 16, 2004 Share Posted September 16, 2004 Hi Antonio , I think you are on the right track but just use print_r() to inspect the array next time. echo '<pre>' . print_r($HTTP_GET_VARS) . </pre>; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.