Jump to content

1 submit button with differents targets


filippo

Recommended Posts

Hello

 

I'm using a form with a dropdown list. When the user select "Test1" in the dropdown then press the button "Submit" it has to send the data to www.test1.com.

 

When the user select "Test2" in the dropdown then press the button "Submit" it has to send the date to www.test2.com.

 

Also the data they've filled in has to come with.

 

I'm working with a datacheck.php, so when the press submit it post to datacheck.php and there I have following code:

 

<?php

if(isset($_POST['TEST1']) && $_POST['TEST1']== 'Y'){
header("Location: http://mysite.com/sage/page1.php");
}
else {
header("Location: http://mysite.com/sage/page2.php");
}
?>

Link to comment
Share on other sites

you may have to use javascript to make it easy

 

<form action="somepage.html" name="form1">

<select onchange="changeAction(this)">

<option>test 1</option>

<option>test2</option>

</select>

</form>

 

<Script>

function changeAction(obj) {

if(obj.value == 'test1') {

document.form1.action = "http://www.test1.com";

} else if(obj.value == 'test2") {

document.form1.action = "http://www.test2.com";

}

}

</script>

 

 

Second option is ..

doing an auto submit, but even for that you will have to use javascript, compared to that, the above option is easy i guess

 

or you may have to use CURL, but not sure if you want to go to that level.

Link to comment
Share on other sites

you may proceed as like this:

 

As you have stated in your post that you used a dropdown box as an alternative for selecting an option, you could assign each  each option a value as like this-

name='option' value='1'

name='option' value='2'

 

on the datacheck.php

if (!empty($_POST['TEST1']))
{
      if($_POST['option']==1)
              {
                        header(['Location: http://mysite.com/sage/page1.php');
               }
      else
               {
                        header('Location: http://mysite.com/sage/page2.php');
               }
}
else
{ 
        echo 'Please fill in the form';
}

 

Link to comment
Share on other sites

Thanks for your help, unfortunately it doesn't work.  I always get Please fill in the form...

 

So, I'm using following html-code:

 

<form action="handler.php" method="post" target="_blank" name"test1">

<table border="0" cellpadding="1" cellspacing="0" width="100%">

<tr>

<td width="100%"  valign="top">

<p style="margin-top: 0; margin-bottom: 0"> </p>

<p style="margin-top: 0; margin-bottom: 0"><IMG src="../img/arrow.gif" width="9" height="7<tr>

<select><option name="option" value="1">TEST1</option><option name="option" value="2">TEST2</option><option name="option" value="3">TEST3</option>

<option name"option" value="4">TEST4</option>

</select>

</table>

 

 

In my php handler.php code I use:

 

<?php
if (!empty($_POST['test1']))
{
      if($_POST['option']==1)
              {
                        header('Location: http://mysite.com/sage/page1.php');
               }
      else
               {
                        header('Location: http://mysite.com/sage/page2.php');
               }
}
else
{ 
        echo 'Please fill in the form';
}
?>

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.