Viewing 0 reply threads
  • Author
    Posts
    • #7537
      Roy
      Participant

      Hey all,

      I’m quite new to Piklist and lovin’ it so far! 🙂 At the moment I’m building a plugin that is an issue tracker that includes a search form. I’ve created a search form using frontend forms and is displayed in the widget area on the left side of the page. Drop-down choices in the form are: Status and Owner. When I press search, the form is posted using GET and the main part of the page processes the data in a table using the parameters. This is all working fine as long as the search form widget is on the same page as the data table. In these cases the url including the get is is http://case-tracker.com/?status=2&owner=3

      Now when an user is on an individual case page, the url is http://case-tracker.com/case-1. The search widget is still displayed and when search is pressed the URL http://case-tracker.com/case-1/?status=2&owner=3 is used instead of http://case-tracker.com/?status=2&owner=3

      Is there a hook within Piklist that I can use or any other way to modify the URL before the page is loaded, clean the URL and then return it? I’m not using the Redirect option in the form header as the site url changes based on what the user has configured.

      I’ve tried the solution at the following link, but that only seems to work for post requests not get, the get does not seem to trigger th wp_redirect hook.

      How can I get the ID of new post created by front-end form?

      Here’s my code

      case-tracker-plugin.php

      add_filter( 'wp_redirect', 'clean_search_url' );
      function clean_search_url( $location, $status ) {
        if ( strpos( $location, '?') === FALSE ) {          // no get request in url
            return $location;
        }
        else {                                              // URL includes GET, correct url
          $get_parms = substr( $location, strpos($location, '?') );
          return 'http://localhost/case-tracker/' . $get_parms;
        }
      }

      search-case-form.php

      <?php
      /*
      Title: Search Case Form
      Method: get
      Message: Search successfully
      Logged in: true
      */
      
      // status
        piklist('field', array(
          'type' => 'select',
          'field' => 'status',    
          'attributes' => array(
            'wrapper_class' => 'case-search',
          ),
          'choices' => array_merge( array('' => 'Status'), $cpt_statuses)
        ));
      
      //owner
      piklist('field', array(
        'type' => 'select',
        'field' => 'owner',
        'attributes' => array(
            'wrapper_class' => 'case-search',
          ),
        'choices' => array(
           '' => 'Owner'
         )
         + piklist(
          get_users(
            array(
             'orderby' => 'display_name'
             ,'order' => 'asc'
            )
            ,'objects'
          )
          ,array(
            'ID'
            ,'display_name'
          )
         )
      ));
      
      piklist('field', array(
        'type' => 'submit',
        'field' => 'submit',
        'value' => 'Search',
        'attributes' => array(
          'class' => 'wpt-search-submit',
        )
      ));

      Thanks a million

Viewing 0 reply threads
  • You must be logged in to reply to this topic.