Header not to go anywhere

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");	
 }
?>

Just… dont send a header in the if section. If it’s firing the trigger in the else section and you dont think it should, you’ve got a problem with your condition.

the problem is that the form action jumps to the action="agents_jump.php file which has the headers is there a way on the form select option to put if
<option value=“none”>Select</option>
dont jump to the form action page

<?php
if ($_POST['agents']=="none")
{
 echo "You didnt specify an agent.";
 exit;
 }
 else
 {
 header("location:http://www.xxxxxx.co.uk/tv/".$_POST['agents']."/index.php");    
 }
?> 

Hi i managed to just redirect to the same page. one problem thou because the form opens the link into a new tab it redirects same page into the new tab. is there a way to do if none keep on the same tab because the aim is i dnt really want to do anything if selected none stay on the same page is it possible? if so how can i try?
thanks

<?php
if ($_POST['agents']=="none"){
      $last_page = $_SERVER['HTTP_REFERER'];
      header("Location: $last_page");
}
else header("location:http://www.estateagentsonfilm.co.uk/tv/".$_POST['agents']."/index.php");
?>

Stop trying to redirect them somewhere? If you do NOTHING, then they will stay where they are. Default behavior.

Train is coming down a railroad track, towards a switch. The switch is currently set to point the train to the north (current page), the other direction is to the east (index). In order to make the train go north… dont touch anything :stuck_out_tongue:

yeah but if the option on the form has values i need to take me to the other page (agents_jump.php)
like is there a way i can if none when click button check if value none?? make button dont do anything but if option has value then redirect to new agents_jump.php page cz i cnt figure how to

<form id="agents" action="agents_jump.php" method="post" name="agents" target="_blank" style="margin:0;">
<option value="none">Select</option>
<option value="one">Select</option>
<option value="two">Select</option>
               <input class="view_agents" id="tvoption" type="image" src="images/viewagents.gif" alt="TV OPTION" name="tvoption">

just try this script

<?php
if ($_POST['agents']=="none")
{
 print "<script>";
 print " self.location='yourfilename.php'";
 print "</script>";

 }
 else
 {
 print "<script>";
 print " self.location='http://www.xxxxxx.co.uk/tv/$_POST['agents']/index.php'";
 print "</script>";	
 }
?>

[/QUOTE]

You could add some Javascript to disable the button when ‘none’ is the option selected…or just put your code into the same page as that form, wrap it in a if isset $_POST[‘agents’], and then have the form action to itself.

And then as soon as someone without javascript enabled visits your site, your code stops working :smiley:
Yeah… no. Bad idea. When this can be accomplished using pure PHP, using javascript just makes it less effective.

yeah that would previous script would work fine the problem would be still jumps into a new tab which is what i am trying to avoid i have also tried to avoid javascript but it seems like one of the choice would be

<script type="text/javascript">
	function checkAgent() {
		if (document.getElementById('agent_select').selectedIndex == 0) {
			alert('Please select an Agent');
			return false;
		}
		return true;
	}
 <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();">
</script>

but even that function not working and i would still keep the header on the next file so if javascript disable it would simple redirect using the header
so on the header page i would have

<?php
if ($_POST['agents']=="none"){	
      $last_page = $_SERVER['HTTP_REFERER'];
      header("Location: $last_page");

}
else header("location:http://www.xxxxx.co.uk/tv/".$_POST['agents']."/index.php");
?>

but the javascript function is not even working do you know anything about javascript can you spot whats wrong with the above function that is not working??

if (document.getElementById(‘agent_select’).selectedIndex == 0) {

                &lt;select name="[COLOR="#FF0000"]agents[/COLOR]" size="1" style="width:160px; font-size:13px;"&gt; 

hums One of these things is not like the other…

yes i did try have the agents name and function name aswell but still send me to the action page from the form even when secet option none??

might have to be “onSubmit” rather than onsubmit, and you forgot to close your <script> tag.

But you should be handling this from PHP. Have the form action set to ‘’, and put the code you’ve got in agents_jump.php into the page you want to jump from, wrapped in if(isset($_POST[‘agents’])) { … }

on the submit button do i need to name name= submit too cz at moment the submit button is like this

  <input class="view_agents" id="tvoption" type="image" src="images/viewagents.gif" alt="TV OPTION" name="tvoption"  border="0"   onclick="jwplayer().stop();">

This isn’t entirely accurate. Unless PHP is told to do otherwise it sends HTTP Header 200 Ok! and is supposed to send a new body.

When a user gets a form wrong it is tradition to resent the form to the user with the bad field highlighted.

Yes, when I say ‘stay where they are’, i meant the form processing page (which, in most cases, is the same page as the form, so that if the form IS bad, you dont have to ‘go anywhere’, you just let the form page reproduce itself.)

@start lion thanks for the help got what i’ve done is i set a javascript alert box when select option == none so stays on the same page but also left the action page with a header if select option equal none to redirect to the same page this way even if the javascript is disable will take to that page and do a similiar job thank you very much