Jump to content

Header not to go anywhere


Lisa23

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/248020-header-not-to-go-anywhere/
Share on other sites

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

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 :)

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

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..

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>

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();">

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.