3

I am a customer service assistant and I wanted to make a simple form to check the price of products on the webpage, without having to load the whole homepage.

The website is www.homebase.co.uk, and the search URL is http://www.homebase.co.uk/en/homebaseuk/searchterm/.

I want to make a form where it will add the text entered in the form after /searchterm/ without the question mark.

EG if I type in 775199 and press submit/search it will navigate to http://www.homebase.co.uk/en/homebaseuk/searchterm/775199.

Thanks so much for your help all :)

I really appreciate it!

adam smith
  • 41
  • 4
  • 1
    Possible duplicate of [How to make Clean URLs](http://stackoverflow.com/questions/34048235/how-to-make-clean-urls) – Siim Kallari May 01 '16 at 06:58
  • Perhaps....not possible duplicate. His question does not necessarily require dealing with HTACCESS File. His question was clear (to me) that he wants the "search_term" appended to the URL in the format he showed us. This could easily be achieved by using PHP header function. He is not intent on trying to REWRITE URL as he is on REDIRECTING to an existing URL only with "search_term" appended to it in the format: http://www.homebase.co.uk/en/homebaseuk/searchterm/775199 where 775199 is the "search_term". See the answer below... – Poiz May 01 '16 at 07:49
  • @poiz yes you're correct. it wasn't to do with the htaccess. :) thanks for your help – adam smith May 03 '16 at 13:08

2 Answers2

2

Assuming you are using PHP. I think what you want to do is this:

<?php
    //THIS IS THE SAME PAGE WHERE YOUR SEARCH FORM EXISTS
    $searchPage = "http://www.homebase.co.uk/en/homebaseuk/searchterm/";
    $formAction = "./";    //FORM IS SUBMITTED BACK TO ITSELF...
    if(isset($_POST['search_term']){
        //BUILD THE REDIRECTION LINK BASED ON THE DEFAULT SEARCH PAGE: $searchPage . $_POST['search_term'])
        //AND THEN REDIRECT TO THE REDIRECTION LINK 
        header("location: " . $searchPage . htmlspecialchars(trim($_POST['search_term'])) );
        exit;
    }    

Your HTML Form might look something like this:

<form method="POST" action="<?php echo $formAction; ?>" >
    <input type="text" name="search_term" id="search_term" value="" class="search_term" />
    <input type="submit" name"submit" id="submit" class="submit" value="Search" />
</form>
Poiz
  • 7,611
  • 2
  • 15
  • 17
1

Okay, so I solved the problem:

<style type="text/css">
.biga {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 36px;
    color: #F90;
    background-color: #FFF;
    border: medium solid #000;
}
}
.centerpoint {
    text-align: center;
}
</style>
<title>Product Search</title>
<p>
<div class="centerpoint"> <span class="centerpoint">
<input name="prog_site" type="text" class="biga" id="prog_site" value="" />
  <a href="http://"
    onclick="this.href=(
                       'http://www.homebase.co.uk/en/homebaseuk/searchterm/' + document.getElementById('prog_site').value)"
    target="_blank">
  <input name="so_link" type="button" class="biga" value="Search Product">
  </a>
  </p>

  </span></div>

This is the code I used. Thanks for all of your help!

adam smith
  • 41
  • 4