Plugin

Developer
Supported

EE 1
EE 2
GET Variable to Segment URL Redirect

Back to this add-on's main page
View Other Add-ons From Laurence Cope

     

You must be logged in to post.

Problems implementing this..

Feature Request

madmonkjoe
madmonkjoe

This is exactly the plugin I need to solve a project problem, but I cannot get it to work. It doesn’t do anything, and I’m sure its my own mistake but I cannot find any other helpful tidbits on this..

My form is:

<div id="sidebar">
               <
div class="aliance">
                  <
h2>Clergy</h2>
                  <
a href="{path='PCP/partner_congregations/'}" class="more">Show All</a>
                  <
ul>
                     <
li><a href="http://alliance-marketing.madmonkdev2.com/index.php/PCP/congregation_list?State=21">Sort By</a>
                     <
form  action="{path='PCP/congregation_list'}" method="get">
                     <
select name="State">
                       
{exp:gwcode_categories cat_id="16" incl_self="no"}
                           
<option value="{cat_id}">{cat_name}</option>
                       
{/exp:gwcode_categories}
                       
</select>
                       <
input type="submit" value="Submit" />
                     </
form>
                     </
li
                  </
ul>
               </
div

Here’s the plugin code:

{exp:get_segment_redirect get_variable=“State” base_url=/PCP/”} 

The URL it should be redirecting but doesn’t:

http://blahblahblah.com/index.php/PCP/congregation_list?State=17 
Amity Web
# 1
Developer
Amity Web

Hmm, strange. I tested this again today and works fine for me. I have tested this on EE 2.5 and EE 2.6. What version do you have? The code is very simple, it just utilises a $this->EE->functions->redirect() function if the get_variable parameter is passed.

This code should be at the top of the template file congregation_list. Is it?

One thing I just noticed… I do not use index.php in my URLs, I removed it. I notice you have it. The base_url parameter gets added to the front of the redirect, so it would be redirected to /PCP/ but if you use index.php then this wont work for you, so your base_url should be /index.php/PCP/ BUT this would not result in “nothing” happening, you would get a page not found or something. So that may not be the issue.

madmonkjoe
# 2
madmonkjoe

I’m running the latest EE version available, so 2.6.x..  Right, index.php is showing up and that is actually on my to-do list. If I were to remove index.php or include it in the base url path you don’t think it would change anything?

madmonkjoe
# 3
madmonkjoe

Also yes, it is at the top of the file in that template.

Amity Web
# 4
Developer
Amity Web

You said nothing happens when you go to the page. But if you had the base_url wrong, you will still be redirected, just not to the right page, so I dont think that is the issue.

Your issue sounds like its just not calling the plugin. The plugin code is quite simple, it boils down to this… if there is a GET variable named the same as the get_variable parameter value you pass in the plugin, it will redirect to the /base_href/variable_name/variable_value

So because you are passing a GET variable called State, then in the plugin you state the get_variable name is State, then it should redirect to /base_url/State/17

If its not redirecting to anywhere it sounds to me like the plugin is not being called for some reason

Any chance you can email me your template code? I would even be happy to login and take a look if you were Ok to give admin access, but understand if not.

madmonkjoe
# 5
madmonkjoe

Well, remote access is impossible I’m testing locally right now. But I can certainly email you the pertinent templates.

Where should I email them too?

madmonkjoe
# 6
madmonkjoe
Amity Web - 14 August 2013 08:46 AM

You said nothing happens when you go to the page. But if you had the base_url wrong, you will still be redirected, just not to the right page, so I dont think that is the issue.

Your issue sounds like its just not calling the plugin. The plugin code is quite simple, it boils down to this… if there is a GET variable named the same as the get_variable parameter value you pass in the plugin, it will redirect to the /base_href/variable_name/variable_value

So because you are passing a GET variable called State, then in the plugin you state the get_variable name is State, then it should redirect to /base_url/State/17

If its not redirecting to anywhere it sounds to me like the plugin is not being called for some reason

Any chance you can email me your template code? I would even be happy to login and take a look if you were Ok to give admin access, but understand if not.

Or.. Would it be better if I just posted the template code here?

Amity Web
# 7
Developer
Amity Web

Feel free to post it, I was hoping to upload it to a site I have. If there are any embeds I should have those too, in case something somewhere else is conflicting.

Are you familiar with PHP? What about editing my plugin itself so instead of the main logic just output something, I usually just do an echo “YES!”; or something to show me its working! If that shows then we know the plugin is being called, if it doesnt show then the plugin is not even being called, for some reason.

This template file is definately being called isnt it? Have you made sure what you enter on this template file is being output to the page, just to be sure?

madmonkjoe
# 8
madmonkjoe

The template itself is fully operational yes, I know for a fact it’s working entirely.


Here is the template with the code for the plugin.

{exp:get_segment_redirect get_variable=“state” base_url=/index.php/PCP/”}
<!-- header -->
<!
doctype html>
<
html>
<
head>
   <
meta charset="utf-8">
   <
title>{title}</title>
   <!-- 
javascripts -->
   
[removed][removed]
   [removed][removed]
   
<!-- end javascripts -->
   <!-- 
stylesheets -->
   <
link media="all" rel="stylesheet" type="text/css" href="{stylesheet='CSS/all.css'}">
   <!--
[if IE 8]><link rel="stylesheet" type="text/css" href="{stylesheet='CSS/ie8.css'}" media="screen"/><![endif]-->
   <!-- 
end stylsheets -->
</
head>
<
body>
 <
div id="wrapper">
      <
div class="w1">
         <
header id="header">
            <
div class="top-bar">
               <
div class="holder">
                  <
strong class="logo"><a href="{path='Home/Index'}">Lorem Ipsum Dolar Secretariat</a></strong>
                  <
form action="#" class="search-form">
                     <
input placeholder="Search" type="search" />
                     <
input type="submit" value="Search"/>
                  </
form>
                  <
ul class="top-nav">
                     <
li><a href="{path='Home/Index'}">Home</a></li>
                     <
li><a href="#">Give</a></li>
                     <
li><a href="#">Calendar</a></li>
                     <
li><a href="#">Ministry Opportunities</a></li>
                     <
li><a href="#">Get e-News</a></li>
                     <
li><a href="#">Contact</a></li>
                  </
ul>
               </
div>
            </
div>   
            <
nav id="nav">
               <
ul>
                  <
li><a href="#">our<span>Lorem</span></a></li>
                  <
li><a href="{path='NewsAndEvents/Index'}">News &amp;<span>Events</span></a></li>
                  <
li><a href="{path='PCP/Index'}">Peoplecommunites <span>&ampPartners</span></a>
                     <
ul>
                        <
li><a href="{path='PCP/alliance_blog'}">Alliance Blog</a></li>
                        <
li><a href="{path='PCP/clergy'}">Endorsed and Recognized Clergy</a></li>
                        <
li><a href="#">Communities</a></li>
                        <
li><a href="#">Leadership</a></li>
                        <
li><a href="#">Ministry Partners</a></li>
                        <
li><a href="{path='PCP/partner_congregations'}">Partner Congregations</a></li>
                        <
li><a href="#">Partnerships</a></li>
                        <
li><a href="#">Students</a></li>
                        <
li><a href="#">Theology Schools</a></li>
                     </
ul>
                  </
li>
                  <
li><a href="#">Alliance <span>Stories</span></a></li>
                  <
li><a href="#">Prayers with <span>The People</span></a></li>
                  <
li><a href="#">Ways to <span>Give</span></a></li>
                  <
li><a href="#">Alliance <span>Connect</span></a></li>
               </
ul>
            </
nav>
         </
header>   
<!-- 
end header -->
   <!-- 
social networks -->
   <
ul class="social-networks">
      <
li class="rss"><a href="#">rss</a></li>
      <
li class="tweeter"><a href="#">tweeter</a></li>
      <
li class="facebook"><a href="#">facebook</a></li>
      <
li class="vimeo"><a href="#">vimeo</a></li>
</
ul>
   <!-- 
end social networks -->
         <
div id="main">
            <
div id="content" class="add">
               <
div class="heading">
                  <
a href="#" class="btn-share"><img src="{images}btn-share.png" alt="Image Description" width="104" height="23"/></a>
                  <
h1>PARTNER CONGREGATIONS {exp:low_alphabet:uppercase text="{segment_3}"}</h1>
               </
div>
               <
class="allianceFont">Did you know the Alliance partners with congregations and theology schools in 28 statesThere are more Alliance congregations in Ohio than in Tennesseemore in New York than in Mississipimore in California than in Floridamore in Massachusetts than in South Carolina?</p>
               <
class="allianceFont">We hope you can find an Alliance partner congregation near you in the listing belowTo learn more about th e communities who are a part of the Alliancevisit the <a href="#">Alliance stories page</a>.
               <
ul class="articles">
                  <
div class="index">
                   
{exp:low_alphabet:azlist channel="pcp_congregations" alpha_field="congregation_name"}
                     
<a href="{path='PCP/congregation_list/{low_alphabet_url}'}">{low_alphabet_label}</a>
                  
{/exp:low_alphabet:azlist} 
                 
</div>
                  
{exp:low_alphabet:entries channel="pcp_congregations" limit="12" paginate="bottom" alpha_filter="{segment_3}" orderby="congregation_name" category="{segment_4}"}
                     
<li>
                        <
img src="{congregation_image}" alt="Alliance News and Events" width="151" height="150" class="align-right">
                        <
h2>{title}</h2>
                        <
ul class="info">
                           <
li class="location"><a href="#">{organization}</a></li>
                           <
li><a href="#">{event_and_news_location}</a></li>
                        </
ul>
                        <
p>{congregation_summary}</p
madmonkjoe
# 9
madmonkjoe
<a href="{title_permalink=" class="more">More Info</a>
                     </
li>
                       
{paginate}
                          {pagination_links}
                           
<ul class="pagination">
                            
{first_page}
                             
<li><a href="{pagination_url}">First Page</a></li>
                            
{/first_page}
                            {previous_page}
                             
<li class="prev"><a href="{pagination_url}">Previous Page</a></li>
                            
{/previous_page}
                            {page}
                             {if current_page}
                              
<li class="active"><a href="{pagination_url}">{pagination_page_number}</a></li>
                             
{/if}
                             {if 
!current_page}
                              
<li><a href="{pagination_url}">{pagination_page_number}</a></li>
                             
{/if}
                            {
/page}
                            {next_page}
                             
<li class="next"><a href="{pagination_url}">Next Page</a></li>
                            
{/next_page}
                            {last_page}
                             
<li class="last"><a href="{pagination_url}">Last Page</a></li>
                            
{/last_page}
                           
</ul>
                          
{/pagination_links}
                       {
/paginate} 
                   {
/exp:low_alphabet:entries}
               
</ul>
            </
div>
            <!-- 
sidebar start -->
            <
div id="sidebar">
               <
div class="aliance">
                  <
h2>Clergy</h2>
                  <
a href="{path='/PCP/partner_congregations/'}" class="more">Show All</a>
                  <
ul>
                     <
li><a href="http://alliance-marketing.madmonkdev2.com/index.php/PCP/congregation_list?State=21">Sort By</a>
                     <
form name="sidebarForm" action="{path='/PCP/congregation_list'}" method="get">
                     <
select name="state">
                       
{exp:gwcode_categories cat_id="16" incl_self="no"}
                           
<option value="{cat_id}">{cat_name}</option>
                       
{/exp:gwcode_categories}
                       
</select>
                       <
input type="submit" value="Submit" />
                     </
form>
                     </
li
                  </
ul>
               </
div>
              <!-- 
sidebar end -->
               <
div class="event">
                  <
img src="{images}img21.jpg" alt="Image Description" width="212" height="119"/>
                  <
div class="details">
                     <
strong class="title"><a href="#">Waging in Peace in Palestine</a></strong>
                     <
p>WashingtonDC</p>
                     <
div class="date">
                        <
time datetime="11-10">11/10</time>-<time datetime="11-12">11/12</time>
                     </
div>
                     <
a href="#">More Info</a>
                  </
div>
               </
div>
               <
div class="video">
                  <
a href="#">
                     <
img src="{images}img22.jpg" alt="Image Description" width="214" height="131"/>
                     <
span>Play Video</span>
                  </
a>
                  <
p>Lorem Ipsum Dolar.</p>
               </
div>
            </
div>
         </
div>
      </
div>
   </
div>
    <!-- 
footer --> 
   <
footer id="footer">
      <
ul>
         <
li>&copy2012 Alliance of Baptists</li>
         <
li>3939 LaVista RoadSuite E-122</li>
         <
li>AtlantaGA 30084</li>
         <
li>866.745.7609</li>
         <
li>866.745.7609 (fax)</li>
         <
li><a href="mailto:">Email Dummy</a></li>
      </
ul>
   </
footer>
   <!-- 
end footer -->
</
body>
</
html
madmonkjoe
# 10
madmonkjoe

Also, “State” is now “state”. I was monkeying around with the names to see if maybe for some inexplicable reason it was unfriendly towards caps.

All includes\embeds have been filled in for the posted template up above per your request.

Also, I assume that it’s atleast partially working given that the tag up top (the code for the plugin) isn’t outputting as a literal string. It’s entirely absent from the page when it renders for me. It just won’t work.

Plugins are being used on this page, like Low Alphabet.

Amity Web
# 11
Developer
Amity Web

In the top of your code, the quotes are different to the rest in your template:
{exp:get_segment_redirect get_variable=“state” base_url=”/index.php/PCP/”}

Can you replace those open/close quotes with straight ones “

I wonder if in your copy and paste of my code, the quotes were switched. Sometimes editors can do that. I hate those open/close quotes they pop up often when copying and pasting.

madmonkjoe
# 12
madmonkjoe
Amity Web - 14 August 2013 07:01 PM

In the top of your code, the quotes are different to the rest in your template:
{exp:get_segment_redirect get_variable=“state” base_url=”/index.php/PCP/”}

Can you replace those open/close quotes with straight ones “

I wonder if in your copy and paste of my code, the quotes were switched. Sometimes editors can do that. I hate those open/close quotes they pop up often when copying and pasting.

Well, it works now. I feel like a complete idiot.

Amity Web
# 13
Developer
Amity Web

No worries, it happens to me which is how I know!

madmonkjoe
# 14
madmonkjoe

A thousand thanks sir, this plugin is marvelous! Works flawlessly now. Made my life a heck of a lot easier.