I have a custom Views search_form_alter() Hook
function ubercart_prod_search_form_alter(&$form, $form_state, $form_id) {
// Load up the $view objects to work with
if (isset($form['#parameters'][1]['view'])) {
$view = $form['#parameters'][1]['view'];
}
switch ($form_id) {
case 'views_exposed_form':
if ($view->name == 'searchproducts') {
// Do range selector filter on 'sell_price'
ubercart_prod_search_range_to_select('sell_price', array( // Views 'field name' = sell_price
'0,999' => 'Less than $1,000',
'1000,1999' => '$1,000 - $1,999',
'2000,3999' => '$2,000 - $3,999',
'4000,6999' => '$4,000 - $6,999',
'7000,999999' => '$7,000 or greater',
), $form, $form_state);
// Do range selector filter on 'art_height'
ubercart_prod_search_range_to_select('art_height', array( // Views 'field name' = art_height
'0,499' => 'Less than 50cm high',
'500,999' => '50 - 99cm',
'1000,1999' => '100 - 199cm',
'2000,99999' => '200cm or greater',
), $form, $form_state);
// Do range selector filter on 'art_height'
ubercart_prod_search_range_to_select('art_width', array( // Views 'field name' = art_width
'0,499' => 'Less than 50cm wide',
'500,999' => '50 - 99cm',
'1000,1999' => '100 - 199cm',
'2000,99999' => '200cm or greater',
), $form, $form_state);
$form['allterm_node_tid_depth']['#options']['All'] = t('All Artists'); // Change 'All' to 'All Artists'
// $form['art_media']['#options']['All'] = t('All media types'); // Change 'All' to 'All Media'
$form['art_height']['#options']['All'] = t('Any Height'); // Change 'All' to 'All Heights'
$form['art_width']['#options']['All'] = t('Any Width'); // Change 'All' to 'All Widths'
$form['sell_price']['#options']['All'] = t('All prices'); // Change 'All' to 'All Prices'
$form['submit']['#value'] = t('Search Art'); // Change 'Submit' button to 'Search'
}
break;
}
}
Showing only a part of the above...
Problem: the Views QUERY only returns results for numeric data, but not the '<Any>'.
If I over-ride the page URL for the Views query from say
URL/searchproducts?sell_price=All
URL/searchproducts?sell_price=0%2c1000
The query works fine, otherwise the result is blank.
More info, later, if you need.
Comments
Comment #1
Peter Bowey commentedThe rest of the code:
Comment #2
Peter Bowey commentedThis is how the Query looks:
Comment #3
Peter Bowey commentedManually running the above Query in MySQL also returns no results!
However, this modified MySQL Query works:
So what do do to get Views to do that [range]?
Peter
Comment #4
Peter Bowey commentedThe above code worked fine with older MySQL + PHP
Comment #5
dawehnerSupport questions can't be critical , because, well they don't break views for thousands of sites.
As you say this is a bug which only exists on php 5.4, do you have any suggestion how to be able to reproduce this without your custom code? Your custom code for example could have this bug as well. I didn't saw something which is that obvious wrong and could cause the problem.
The best thing you could do, at least to get help by us, is to describe the problem in a way that everyone can just see this bug on a clean normal drupal installation. Installing php 5.4 wouldn't be a problem for me, though, but i currently use 5.3 just for convenience.
Comment #6
Peter Bowey commentedHistory / Background:
New Server: PHP 5.4.0 + MySQL 5.5.12 @ InnoDB
Old Server: PHP 5.2.17 +MySQL 5.0.51a @ MyISAM
Drupal [Pressflow] 6.25 + MySQL Database was migrated from an older Server -
with PHP 5.2.17 +MySQL 5.0.51a to New Server with PHP 5.4.0 + MySQL 5.5.12.
Notes: Prior to this all current D6 module updates applied.
The custom Views search_form_alter() Hook run correctly
on the old server; but on the new server the default
<All>returned no query results for numeric ranges . Works
fine on selected values [numeric].
With the Views search_form_alter(), Text ranges
<All>is fine!Comment #7
dawehnerSome other link you might want consider to provide more valuable information: http://drupal.org/node/571990
Comment #8
Peter Bowey commentedSo I can debug this issue, in what part of 'Views' is the
page URL/searchproducts?sell_price=All translated to:
Comment #9
Peter Bowey commentedUsing grep, I suspect I need to start debug in one of the following Views files:
modules/taxonomy/views_handler_filter_term_node_tid_depth.inc
modules/taxonomy/views_plugin_argument_validate_taxonomy_term.inc
Comment #10
Peter Bowey commentedAfter a lot of debugging, I have determined that the issue lies with the
#element_validate which run's a function before the submission.
At this point, using the D6 views 'between' filter, the very first value [character]
of the ['max'] value is inserted - and over writes the first value [character]
of the ['min'] value. Effectively 'corrupting' the intended 'min' value of the 'between'
Views filter. Only the very first character value of 'min' is effected - and it always uses
the very first character of the 'max' value - submitted.
At the moment, I cannot back-trace enough code to see what is causing this.
Comment #11
Peter Bowey commented** Issue Resolved **
This is a Views 6.x-2.x-dev PHP 5.4.x Bug.
Tested, back-traced, and proven!
Fix / Patch: [crude-but it works]
--------------------------------------
In the Views Tree: file => /handlers/views_handler_filter_numeric.inc
Change these lines:
To this:
(basically, this 'change' checks that the item is an array - first).
The actual PHP5.4.x warning:
Illegal string offset 'min' in views_handler_filter_numeric->value_form() (line 193 + 196 of /var/www/virtual/artlogic.com.au/sites/all/modules/views/handlers/views_handler_filter_numeric.inc).
I originally ignored this simply because it only maked as a PHP 'warning', but it turns out that while PHP 5.3.x would overlook if an item was not an array, PHP 5.4.x it now throws this warning [which becomes an code error] when it’s expecting an array (for 'min' in this case).
This is the patch that got things working for me. I know the developers will improve it.
Moving this thread to a Views 'Bug' status! Then possibly a patch (or a series of for PHP 5.4.x)
Comment #12
merlinofchaos commentedON what grounds is this critical?
Comment #13
Peter Bowey commentedWell, PHP 5.4.1 is to be released on the 26th of April 2012.
Some Drupal users /innovators may already be moving to PHP 5.4.0.
(I have -though there are not many - yet)
Was marked as 'Critical' because Views will 'break code' under PHP 5.4.x (read 'error').
Comment #14
Peter Bowey commentedSee http://drupal.org/node/1543434 for a full update
Comment #15
merlinofchaos commentedDoes it whitescreen?
Comment #16
Peter Bowey commentedRefer #15
Quote: "Does it whitescreen?"
Answer:
Before the patch, no results are returned - on the above 'Views query'.
Not it does not 'whitescreen' in that sense, just no data on the return()
Comment #17
michaelfavia commentedI didnt expect to open a 3 year old case this morning but I had a deep dive with the same type of form alter in D7 and ran into the same issue with php 5.4 on views 3. His suggested fix (while applied to a different line and context) worked as well but not for any reason i understand yet. Im goign to throw it in a debugger and see what i can figure out but basically the key seemt o be in preventing the middle line in this if clause from executing. THe last is_array() is what he added but from what i can tell it could just as easily be FALSE because i dont see a condition in which it is an array.
/handlers/views_handler_filter_numeric.inc
Once this line is removed from the process the select checkbox is correctly applied and automatically selected as the "last" value on filter page refreshes/submissions. If anyone can comment to the purpose of:
Comment #18
chris matthews commentedThe Drupal 6 branch is no longer supported, please check with the D6LTS project if you need further support. For more information as to why this issue was closed, please see issue #3030347: Plan to clean process issue queue