Mod Rewrite with POST

Discussion in 'PHP' started by adamjblakey, Mar 18, 2008.

  1. #1
    Hi,

    I have to list menus with date in both, what i want to do is when the user select data from them both and hits search i want it to come back with a url like this:

    www.website.com/post[list1]/post[list2]/

    How would i do this?

    Cheers,
    Adam
     
    adamjblakey, Mar 18, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    hI
    you will need to write javascript which will change values of hidden fields(whatever maximum number of options in menu)

    just using javascript pass the data to hidden fields



    then the form will take the user to url like this

    www.website.com/abc.php?p1=aaaaa&p2=bbbbb

    then using mod rewrite you can convert this to desired url which will be translated to above url

    Regards

    Alex
     
    kmap, Mar 18, 2008 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    I get what you mean, How would i go about this though as i have never used javascript in this way before.

    I assume it would be something like this:

    
    <select name="service" id="service" onchange="changethis(name)>
    <option value="Test" selected="Test">Test</option>
    
    <select name="service2" id="service2" onchange="changethis(name)>
    <option value="Test" selected="Test">Test</option>
    
    <a href="http://www.website.com/updatevaluehere/updatesecondvaluehere/"><img src="image.jpg"></a>
    
    Code (markup):
    Cheers,
    Adam
     
    adamjblakey, Mar 18, 2008 IP
  4. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #4
    Can anyone help me with this one?
     
    adamjblakey, Mar 19, 2008 IP
  5. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What you could do is use some sort of intermediate page, like this:
    <form action="search.php" method="post">
    <input name="service" type="text" />
    <input name="service2" type="text" />
    <input type="submit" />
    </form>
    PHP:
    search.php:
    <?php
    
    header('Location: /search/' . urlencode($_POST['service']) . '/' . urlencode($_POST['service2']) . '/');
    
    ?>
    PHP:
    Haven't tested that either and it'll probably end up more complicated than that but it's an idea. Then you'll just need mod_rewrite to access the page above
    
    RewriteEngine On
    RewriteRule ^/search/([a-z0-9]+)/([a-z0-9]+)/?$ searchresults.php?service1=$1&service2=$2
    
    PHP:
    ^^ Take that with a grain of salt
     
    decepti0n, Mar 19, 2008 IP