filippo Posted February 4, 2011 Share Posted February 4, 2011 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"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/226679-1-submit-button-with-differents-targets/ Share on other sites More sharing options...
jaikar Posted February 4, 2011 Share Posted February 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/226679-1-submit-button-with-differents-targets/#findComment-1169824 Share on other sites More sharing options...
litebearer Posted February 4, 2011 Share Posted February 4, 2011 might also show us the form, it could help in providing an alternate solution Quote Link to comment https://forums.phpfreaks.com/topic/226679-1-submit-button-with-differents-targets/#findComment-1169828 Share on other sites More sharing options...
spaceman12 Posted February 4, 2011 Share Posted February 4, 2011 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'; } Quote Link to comment https://forums.phpfreaks.com/topic/226679-1-submit-button-with-differents-targets/#findComment-1169846 Share on other sites More sharing options...
filippo Posted February 4, 2011 Author Share Posted February 4, 2011 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'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/226679-1-submit-button-with-differents-targets/#findComment-1169874 Share on other sites More sharing options...
litebearer Posted February 4, 2011 Share Posted February 4, 2011 Since those are the only two choices in your form, why not just make them individual links? Quote Link to comment https://forums.phpfreaks.com/topic/226679-1-submit-button-with-differents-targets/#findComment-1169886 Share on other sites More sharing options...
filippo Posted February 4, 2011 Author Share Posted February 4, 2011 Sorry, I have other inputs but didn't put them here to make to code not to long Quote Link to comment https://forums.phpfreaks.com/topic/226679-1-submit-button-with-differents-targets/#findComment-1169888 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.