String replace &sn= with +

Discussion in 'PHP' started by Johnburk, Nov 3, 2010.

  1. #1
    I have made a dropdown search option when visitors can select from several words and search for that.

    The problem is that with every word extra data is added.

    With one word it is

    /?s=keyword

    With 2 words it is
    /?s=keyword&sn=keyword2

    but it should be

    /?s=keyword+keyword2

    The form is as followed


    <form role="search" method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>">
      <div>
        <label class="screen-reader-text" for="s">Search for:</label>
    Type
    <select name='s' id='type' class='postform' >
      <option value='' selected='selected'>All</option>
      <option class="level-0" value="dog">Dog</option>
      <option class="level-0" value="cat">Cat</option>
    </select>	
    
    Color
    <select name='sn' id='color' class='postform' >
      <option value='' selected='selected'>All</option>
      <option class="level-0" value="red">red</option>
      <option class="level-0" value="white">white</option>
      <option class="level-0" value="green">green</option>
    </select>	
    
       <input type="submit" id="searchsubmit" value="Search" />
      </div>
    </form>
    Code (markup):
    Is there a way to replace &sn= with + ?
     
    Last edited: Nov 3, 2010
    Johnburk, Nov 3, 2010 IP
  2. KingOle

    KingOle Peon

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I'm looking at your form and you have named both your select as "s". Assuming you can only make a max of two choices, one of the selects should be named something else. I'm not sure where you are getting sn from.

    But maybe I'm misunderstanding something. How do you expect to get both variables from the URL with a + inbetween them?
     
    KingOle, Nov 3, 2010 IP
  3. Johnburk

    Johnburk Peon

    Messages:
    777
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You are right. I changed the second one to sn.

    The current url is
    /?s=keyword&sn=keyword2

    So perhaps it is possible with with string replace or JS to change the secons &sn= to +
     
    Johnburk, Nov 3, 2010 IP
  4. KingOle

    KingOle Peon

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Can I ask why you want to change it to a +?
     
    KingOle, Nov 3, 2010 IP