views:

60

answers:

4

I have a form, depending on the selected value of my <select> box I would like to send to a different page.

I do not know the best way to do this, but I am thinking that maybe the best way is to have an intermediate page to always post to, then have the intermediate page check the value sent from the <select> box and forward the POST values to a different page depending on what it is. If this is the best way, how can I do that? If not, what is the best way?

Thanks!!

+1  A: 

that certainly would be the best method for user compatibility.

you could do it using the HTTP redirect header, e.g.

header("Location: http://www.example.com/");

which should be called before there is any output to the page.

That way the user won't even land on the intermediate page when he presses the forward/back buttons.

the only other option I see would be to use javascript to change the form target or something salong those lines, but that has some caveats (javascript has to be enabled, more complicated code, redirection shouldn't really happen in the view of a page)

Zenon
A: 

i'd use javascript to change the target of the form

if you really want to use php, you should try curl: http://uk2.php.net/curl

FrankBr
+1  A: 
Robert Grant
A: 

javascript

function form_submitted(){
   switch(document.myform.select_name.value){
     case 'whatever':
        document.myform.target.value = "whatever_you_need";
        break;
     case 'whatever2':
        document.myform.target.value = "whatever_you_need_2";
        break;
    }
}

Then either assign this function to the form with the "onSubmit" attribute, or have a button (rather than submit button) that calls that function and add document.myform.submit() at the end of the function.

eCaroth