Lisa23 Posted September 28, 2011 Share Posted September 28, 2011 Hi is there a way that i can set header not go anywhere like the problem with this is that it still goes to the second header is there a way i can set if none do nothing exit? and else do the second header?? <?php if ($_POST['agents']=="none") { header("location:#"); exit; // header("Location: {$_SERVER['PHP_SELF']}"); } else { header("location:http://www.xxxxxx.co.uk/tv/".$_POST['agents']."/index.php"); } ?> Quote Link to comment Share on other sites More sharing options...
freelance84 Posted September 28, 2011 Share Posted September 28, 2011 Not sure i know exactly what your getting at... if 'none' do nothing else header to x? Like this? <?php if ($_POST['agents']=="none") exit(); else header("location:http://www.xxxxxx.co.uk/tv/".$_POST['agents']."/index.php"); ?> Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted September 28, 2011 Share Posted September 28, 2011 you'll want to exit() after the header as well to prevent the rest of the code form executing.. Quote Link to comment Share on other sites More sharing options...
freelance84 Posted September 28, 2011 Share Posted September 28, 2011 Yup sorry missed that: <?php if ($_POST['agents']=="none") exit(); else{ header("location:http://www.xxxxxx.co.uk/tv/".$_POST['agents']."/index.php"); exit(); } ?> Quote Link to comment Share on other sites More sharing options...
Lisa23 Posted September 28, 2011 Author Share Posted September 28, 2011 my problem is that the form works like this <form id="agents" action="agents_jump.php" method="post" name="agents" target="_blank" style="margin:0;"> <option value="none">Select</option> <option value="1">Select</option> <option value="3">Select</option> and the agents_jump.php has the headers but what i want is if none dont jump to the agents_jump.php file or if it has to jump set a header to go back to previous page. has at moment it still jumps to agents_jump.php file showing a blank file <?php if ($_POST['agents']=="none") exit(); else header("location:http://www.estateagentsonfilm.co.uk/tv/".$_POST['agents']."/index.php"); ?> Quote Link to comment Share on other sites More sharing options...
Buddski Posted September 28, 2011 Share Posted September 28, 2011 Something like this? if (isset($_POST['agents']) && $_POST['agents'] != "none") header("Location: http://www.xxxxxx.co.uk/tv/".$_POST['agents']."/index.php"); exit(); } Edit: Ignore me, I thought the agents_jump file was the same file that contained the form code Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted September 28, 2011 Share Posted September 28, 2011 if ($_POST['agents']=="none"){ $last_page = $_SERVER['HTTP_REFERER']; header("Location: $last_page"); } Quote Link to comment Share on other sites More sharing options...
Lisa23 Posted September 28, 2011 Author Share Posted September 28, 2011 almost perfect 1 small problem because the form opens in a new tab i opens the same page in a new tab is there a way if none either open the same page in the same tab or something like that? if ($_POST['agents']=="none"){ $last_page = $_SERVER['HTTP_REFERER']; header("Location: $last_page" same tab); } Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted September 28, 2011 Share Posted September 28, 2011 well you have your form target set to blank, i would recommend getting rid of it so the form always opens in the same tab.. keeping the target blank and changing it upon $_POST['agents'] == "none" would require some JavaScript integration.. we can go that route if you want.. Quote Link to comment Share on other sites More sharing options...
Buddski Posted September 28, 2011 Share Posted September 28, 2011 The short answer is no.. Once the form is submitted the new window is created and PHP cannot access the original window. Instead of using PHP to check that the field hasnt been changed from "none", you could use Javascript to ensure that the field was not left blank. <script type="text/javascript"> function checkAgent() { if (document.getElementById('agent_select').selectedIndex == 0) { alert('Please select an Agent'); return false; } return true; } </script> <form action="agents_jump.php" onsubmit="return checkAgent();" method="post" target="_blank" style="margin:0;"> <select name="agent" id="agent_select"> <option value="none">Select</option> <option value="1">Agent 2</option> <option value="3">Select</option> </select> <input type="submit" value="Submit" /> </form> Quote Link to comment Share on other sites More sharing options...
Lisa23 Posted September 28, 2011 Author Share Posted September 28, 2011 still took me to the other page when click submit button ii it cz i have the submit type has image perhaps <form id="agents" action="agents_jump.php" onsubmit="return checkAgent();" method="post" name="agents" target="_blank" style="margin:0;"> <select name="agents" size="1" style="width:160px; font-size:13px;"> <option value="none">Select</option> <input class="view_agents" id="tvoption" type="image" src="images/viewagents.gif" alt="TV OPTION" name="tvoption" border="0" onclick="jwplayer().stop();"> Quote Link to comment Share on other sites More sharing options...
Lisa23 Posted September 28, 2011 Author Share Posted September 28, 2011 Thank you evryone for the help manage to get the javascript alert to work without sending to next page like if none selected pop up alert box thank you very much Quote Link to comment 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.