2

I try to display a list of content with exposed filter in Drupal 7 and Views 3, I create a page and it works, but I also want to display a map with the filter, so I create a block for the gmap and for get the information about the filter I add a contextual filter with php code like this (where province is the name of the field)

return $_GET["province"];

In Drupal 6 it works this method, but in Drupal 7 I receive this error

Notice: Undefined index: province in eval() (line 1 of /pathtomodule/views/plugins/views_plugin_argument_default_php.inc(49) : eval()'d code).

So where is the error, I return only one argument (I know that I need some control if the code is null, but in this case I )

  • Did you check the parameter is passed through the URL? Is AJAX enabled for that view? – kiamlaluno Aug 6 '11 at 10:00
  • Thanks, i try to enable ajax and disable but there are no change, the same error, the views is a block, because i use data module and for the exposed filter need a page, yes the parameter is passed correct from the url, i also try with this code: if isset($_GET["distance[search_distance]"]) { return $_GET["distance[search_distance]"]; } else { return "100"; } But i receive: Notice: Undefined offset: 1 in location_handler_argument_location_proximity->query() (line 119 of ... – racket Aug 6 '11 at 10:14
1

Notice: Undefined index: province in eval() (line 1 of /pathtomodule/views/plugins/views_plugin_argument_default_php.inc(49) : eval()'d code).

This error occurs when the array key province does not exist. The PHP documentation goes into greater detail - http://www.php.net/manual/en/language.variables.basics.php

Relying on the default value of an uninitialized variable is problematic in the case of including one file into another which uses the same variable name... E_NOTICE level error is issued in case of working with uninitialized variables, however not in the case of appending elements to the uninitialized array. isset() language construct can be used to detect if a variable has been already initialized.

Instead of

return $_GET["province"];

Use isset() logic. Also, you shouldn't be directly accessing $_GET, $_POST or $_REQUEST; best practice is to use drupal_get_query_parameters()

$param = drupal_get_query_parameters();
if (isset($param['province'])) {
  return $param['province'];
}
return NULL;

To address the problem in your comment:

But i receive: Notice: Undefined offset: 1 in location_handler_argument_location_proximity->query()

This is (for all intrinsic purposes) the same as the undefined index; location_handler_argument_location_proximity->query() is expecting an array with at least two elements (offset 0 and 1), and that method expected, but did not receive an array with two elements. It might not even be getting an array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.