How do I redirect the user to some other page, when the view returns empty result?
1See also: drupal.stackexchange.com/questions/37655/…– dreftymacFeb 22, 2017 at 20:21
In your views No results behavior Choose ' Global: Text area ' choose php filter and add the following code.
<?php drupal_goto('node/1'); //path to redirect ?>
Thanks a lot. This is exactly what I did a few minutes ago :)– qasimzeeMay 24, 2013 at 10:42
This has security implications, it requires enabling PHP code through PHP filter, which is generally discouraged. github.com/dreftymac/public.lab/blob/master/topic/d7/… dmid://pageredir_methodic_guard Oct 14, 2016 at 21:15
Better yet do it in your views-view.tpl.php and avoid using PHP in UI like.
<?php if ($rows): ?> <div class="view-content"> <?php print $rows; ?> </div> <?php elseif ($empty): ?> <div class="view-empty"> <?php drupal_goto('some_page'); ?> </div> <?php endif; ?>
if you want to pass query to new url use this for goto
drupal_goto('your_url', array('query'=>array( 'variable_name1'=>'variable_value1', 'variable_name2'=>'variable_value2', 'variable_name3'=>'variable_value3', ...... ... )));
or if you want to goto an anchor on page use this
drupal_goto("node", array('fragment' => $node->nid));