Reputation: 38
I tried this question before and did not supply enough information, so here are more details. I have a page on a hosted site asking the visitor to enter a coded string in a form. When submitted the code builds a file name and grabs some simple data from a text file.
Everything works fine in FF and Safari but when testing this in internet explorer 7 and internet explorer 8, when submitted, the visitor is redirected to the site home page.
This same unexpected redirection is happening elsewhere in the site. I am hoping if I can isolate the issue here I can fix the other instances.
Here is the code:
<?php
session_start();
ob_start;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Advisor Survey - 2012 Predictive Questions</title>
<link href="css/surv_ver2.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/s_table.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="header">
</div> <!-- close header -->
<div id="wrapper">
<div id="mid_cont">
<div id="mid_left">
</div> <!-- close mid_left -->
<div id="mid_col">
<div id="mid_col_inner">
<h2 class="p_head">Scoring Details</h2>
<p class="p_text">Want to learn more about how your site compares to others in your market? We employed tools to evaluate your web site from a high-level marketing perspective.</p>
<p class="p_text">All of our sample tests mimic search engine functionality. Check our site to see where your score falls in the overall Denver market.</p>
</div> <!-- close mid_col_inner -->
</div> <!-- close mid_col -->
<div id="mid_center">
<div id="top_cent">
<img src="images/revenue_subhead.png" />
</div> <!-- close top_cent -->
<div id="mid_cent">
<p class="mid_col_text">Enter the code (no punctuation or spaces) from our communication with you to see your score.</p>
</div> <!-- close mid_cent -->
<div id="bot_cent">
<div id="bot_left">
<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?> " />
<label id="label2">Enter code: </label>
<input type="text" name="code" id="code" />
<input type="submit" name="submit" id="code_submit" />
</form>
</div> <!-- close bot_left -->
<div id="bot_right">
<?php
if (($_POST['submit']) and (empty($_POST['code']))) {
echo "<br/><br/>";
print "<p class=\"spl_p\"> Please select choice!</p>";
}
if (!empty($_POST['code'])) {
$response = $_POST['code'];
echo $response;
$test_name = $response . ".txt";
$test_name = "../id_advisors/$test_name";
if (!file_exists($test_name)) {
echo "Please re-enter code!";
exit();
}
}
if (!empty($_POST['code'])) {
echo $test_name;
// read in the details of the file for each firm
$pointer = fopen("../id_advisors/$test_name", "r");
$data_line = fgets($pointer, 1096);
fclose($pointer);
$file_array = explode("\t", $data_line);
foreach ($file_array as $item) {
$item = $file_array;
$firm_name = $file_array[0];
$mkt_id = $file_array[1];
$site_id = $file_array[2];
$score = $file_array[3];
$pages = $file_array[4];
$traffic_rank = $file_array[5];
$in_links = $file_array[6];
$start_date = $file_array[7];
}
}
?>
<table id="form_2" cellpadding="-3">
<tr><td width="100">Firm name: </td><td><input type="text" name="f_name" id="f-name" value="<?php echo $firm_name; ?>" /></td></tr>
<tr><td width="100">Market ID: </td><td><input type="text" name="mkt" id="mkt" value="<?php echo $mkt_id; ?>" /></td></tr>
<tr><td width="100">URL : </td><td><input type="text" name="url" id="url" value="<?php echo $site_id; ?>" /></td></tr>
<tr><td width="100">Score: </td><td><input type="text" name="score" id="score" value="<?php echo $score; ?>" /></td></tr>
<tr><td width="100">Index pages: </td><td><input type="text" name="pages" id="pages" value="<?php echo $pages; ?>" /></td></tr>
<tr><td width="100">Traffic: </td><td><input type="text" name="traff" id="traff" value="<?php echo $traffic_rank; ?>" /></td></tr>
<tr><td width="100">Inbound links: </td><td><input type="text" name="i_links" id="i_links" value="<?php echo $in_links; ?>" /></td></tr>
<tr><td width="100">Test date: </td><td><input type="text" name="t_date" id="t_date" value="<?php echo $start_date; ?>" /></td></tr>
</table>
</div> <!-- close bot_right -->
</div> <!-- close bot_cent -->
</div> <!-- close mid_left -->
<div id="mid_right">
</div> <!-- close mid_left -->
</div> <!-- close mid_cont -->
<div id="footer">
</div> <!-- footer -->
<div id="sub_foot">
<p>Copyright 2012 | Lighthouse Pacific Group, LLC - All Rights Reserved</p>
</div> <!-- close sub_foot -->
</div> <!-- close wrapper -->
</body>
</html>
Upvotes: 2
Views: 251
Reputation: 1750
You're closing your FORM element on the same line you create it:
<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?> " />
change that to this:
<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?> ">
I'm not sure that will fix your redirect problem specifically, but I know it will cause some problems with your form submission if you don't fix that.
EDIT
OK I overlooked the problem the first time, here's the fix, change the same line of code listed above, but include echo...
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
or to simplify:
<form method="POST" action="<?=$_SERVER['PHP_SELF']?>">
Upvotes: 2