...

View Full Version : passing variables through a link



McNasty
09-21-2005, 12:08 PM
I have an online form with 2 submit buttons.

Unfortunately the form can only be submitted to 1 place.

I need one button to submit to a _self page
The other to submit to a _blank page.

The only way I can think of doing this is to have one button as a link instead

Can I pass posted variables through a link?

Cheers,

tim

NancyJ
09-21-2005, 12:19 PM
yes, if your form has a method of "get" you can submit as a querystring rather than as posted values. You could then redirect to the appropriate page using asp or php and just pass the whole querystring through to the processing page depending which button was pressed

One option to consider (depending on your target audience) is the use of javascript, you can set a forms action in the onclick event of the form buttons.. eg



function changeAction(newaction){
document.formname.action = newaction;
}



<form action = "" method = "post">
<input type = "submit" name = "action1" value = "Button 1" onclick="changeAction('action1.php')">
<input type = "submit" name = "action2" value = "Button 2" onclick="changeAction('action2.php')">
</form>

McNasty
09-21-2005, 01:20 PM
Not to keen on javascript. Can it be done with PHP

NancyJ
09-21-2005, 01:52 PM
not client side.
You would have to reload the page to do it with php. You could post everything through the querystring then redirect to the relevant processing page... eg



if(isset($_POST['button1']){
header("location: page1.php?{$_SERVER['QUERY_STRING']}")
}
else{
header("location: page2.php?{$_SERVER['QUERY_STRING']}")
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum