0

I have a classic view with fields from classic nodes. I have made a custom form that reload the view with parameters :

mypage?nid=168

But to display only the wanted data, my view use CONTEXTUAL FILTERS and need this format :

mypage/168

How can I filter my view from $_GET parameters.

  • what do you mean by classic? Does the form reload something with ajax or simply post to the view. What arguments are you passing to the view from the form? – Daniel Harper Nov 20 '13 at 14:50
2

Hope this will help you,

In Drupal 7 you can achive it by using views php module.

  • Add contextual filter

    enter image description here

  • Select the field using which you want to filter. I'm using Content NID as filter parameter

    enter image description here

  • Add the PHP code for filtering

    enter image description here

  • PHP code

     
    if(isset($_GET['nid']))
        return $_GET['nid'];
    else
        return;
    
  • Just add the param in the URL

    enter image description here

Note :

  • check the permission of views_php module
  • Make the changes as per your requirement.
2

Use "Global: PHP" field to get the required parameter value. If views_php is not installed, then use this link, views_php to install the module and give the permission using admin/people/permissions.

Go to your Views -> CONTEXTUAL FILTERS -> ADD -> Select "Global: PHP" then you can retrieve the parameter using $_SERVER[QUERY_STRING] and retrieve the value.

And also you can use $_GET['nid'] to get the value.

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.