On a recent project we have a page (generated by Views) that has 3 panels with a listing, calendar and map. The map and calendar contains entries for all of the items on the list. However, the number items in the list requires pagination. On the detail page for each entry you can simply use the browser back button to return to the previous page, but you get a warning asking if you’re sure you want to resubmit the form, not ideal. I decided to implement a more elegant method of returning the previous page without having to resumbit the form.
Firstly, I needed to grab some information from the object returned by get_current_view(). I then added a dsm call to the the full PHP header so I could see what’s actually available. Here’s the code to put into the header of the view to get this information…
<?php $view = views_get_current_view(); dsm($view); ?>
…and here’s a screenshot showing the code in place

I could see from the output that there were 2 elements I was interested in, $args=$view->args['0'] (which held the cached view id) and $page=$view->pager['current_page'] (which held the current page the user was on, starting at 0). so far so good.
Next, I also needed a way to concatenate several fields into a table cell (as that was how the output was needed). I drushed Views custom field so that I could rewrite the output of a field with PHP. Custom field is like Views global text on steriods, highly recommended.
After a little more jiggery pokery getiing the other items I needed, I ended up with the following code in my custom field:
<?php $view = views_get_current_view(); $args=$view->args['0']; $page=$view->pager['current_page']; $title=$data->node_title; $loc=$data->location_city; $contact=$data->node_data_field_result_set_id_field_contact_value; $rectype=$data->node_data_field_result_set_id_field_record_type_value; $recid=$data->node_data_field_result_set_id_field_record_id_value; echo "<h3><a href='/record/$rectype/$recid/$args/$page'>$title</a></h3>"; echo "<h4>$loc</h4>"; echo "<p>".htmlspecialchars_decode($data->node_revisions_body)."</p>"; echo "<span class='contact'>$contact</span>"; ?>
As you can see, this takes some of the CCK node values, the node title, node body and views arguments and wraps them up in a url like this:
/record/[rec_id]/[rec_type]/[view_cache_id]/[current_page]
Finally, I needed to adjust my custom module to accept the 2 new parameters (view_cache_id and current_page). Having done that I just had to add a link in my template – I’d already set the vlause to the variables $ref and $page.
echo "<div class='back-to-search'><< Go back to <a href='/dir?$ref&page=$page'><strong>your search results</strong></a></p>";
All done, and a much better user experience as well.



