location redirect problem in dynamic form?
Posted: Fri May 05, 2006 7:01 am
I've done a form which first checks to see if certian fields have been validated. Once the user clicks the submit button the form checks itself and if fields have been entered it then should use the relocation to send to the results page but it doesn't and i can't seem to figure out why. Any ideas?
Test Site
Test Site
Code: Select all
<?php require_once('../Connections/dbConn.php'); ?>
<?php
mysql_select_db($database_dbConn, $dbConn);
$query_subjects = "SELECT * FROM injuries";
$subjects = mysql_query($query_subjects, $dbConn) or die(mysql_error());
$row_subjects = mysql_fetch_assoc($subjects);
$totalRows_subjects = mysql_num_rows($subjects);
?>
<?
$message = " ";
$emailclass = "basictext";
$star = "*";
if ($_POST['sent'] == "1") {
$pattern = '/^[a-z0-9_.-]+@[a-z0-9_.-]+\.[a-z]{2,4}$/i';
$email = $_POST['email'];
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$address = $_POST['address'];
$subname = $_POST['sub_name'];
if (!$name) {
$message = "(*) Indicates that these fields must be entered. You must enter a name.";
$emailclass = "errortext";
}
else if (preg_match($pattern, $email ) == 0) {
$message = "(*) Indicates that these fields must be entered. There was a problem with the email addresses you entered.";
$emailclass = "errortext";
}
else if (!is_numeric($telephone)) {
$message = "(*) Indicates that these fields must be entered. You must enter a telephone number.";
$emailclass = "errortext";
}
else if ( strlen($telephone) < 11 || strlen($telephone) > 11) {
$message = "((*) Indicates that these fields must be entered. The telephone number is not the correct length.";
$emailclass = "errortext";
}
else
header("location: results.php?name=$name&&telephone=$telephone&&email=$email&&address=$address&&sub_name=$subname");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" ><!-- InstanceBegin template="/Templates/personal_injuryv2.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Ashton Morton Slack: Business</title>
<style>
table{ border-top:1px solid #B6B1AB; border-bottom:1px solid #B6B1AB; border-right:1px solid #B6B1AB; border-left:1px solid #B6B1AB;}
td {background-color:#DBD2E5; font:12px Verdana, Arial, Helvetica, sans-serif; color:#000000;}
form {float:left;}
.errortext {
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
color:#FF0000;
}
</style>
<script language="JavaScript" type="text/javascript">
function reload(form)
{
var val=form.main_name.options[form.main_name.options.selectedIndex].value;
self.location='test.php?main_name=' + val ;
}
</script>
<!-- InstanceEndEditable -->
<!-- The following stylesheet import only works for IE5+ and NS6+, earlier browser get text only -->
<style type="text/css" >
<!--
@import url(../css/ams_common.css);
@import url(../css/ams_personal_injury.css);
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<script type="text/javascript" src="../scripts/minmax.js"></script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>
<body class="pageBusiness">
<div class="hideFromCSSBrowsers"><p><a href="#mainContent">Jump to main content</a>. </p><p><strong>You are viewing this site with Style Sheets turned off, or a browser which is not CSS standards compliant. You can still use a basic version of the site. You may wish to consider upgrading to a compatible, such as recent versions of <a href="http://www.microsoft.com/windows/ie/default.mspx" target="_blank">Microsoft Internet Explorer</a> or <a href="http://www.mozilla.org/products/firefox/" target="_blank">Firefox</a>.</strong></p></div>
<div id="headerContainer">
<div id="mainLogo"><a href="/"><img src="../images/!personalinjury/main_logo.gif" alt="ashton morton slack" width="305" height="54" title="ashton morton slack" /></a></div>
<ul id="globalNav">
<?php include('../includes/nav_globalnav.php'); ?>
</ul>
<div id="headerImageBoxes">
<div id="headerImageBoxes-inner">
<a href="../business/index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image6','','../images/!generic/header_box1light.gif',1)"><img src="../images/!generic/header_box1.gif" alt="Business Services" name="Image6" width="58" height="58" id="Image6" /></a> <a href="index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image7','','../images/!generic/header_box2light.gif',1)"><img src="../images/!generic/header_box2.gif" alt="Personal Injury Services" name="Image7" width="58" height="58" id="Image7" /></a><a href="../private-client/index.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image8','','../images/!generic/header_box3light.gif',1)"><img src="../images/!generic/header_box3.gif" alt="Private Client Services" name="Image8" width="58" height="58" id="Image8" /></a></div>
</div>
</div>
</div>
<div id="contentContainer">
<div style="float:left; width: 179px;">
<div class="roundedBox">
<div class="roundedBoxImage"><img src="../images/!personalinjury/mn-pi-top.jpg" width="189" height="99" /></div>
<!-- InstanceBeginEditable name="subnav" -->
<h2 class="subnavSelected"><a href="index.php">Personal injury home</a></h2>
<h2><a href="fee/index.php">No Win No Fee</a></h2>
<h2><a href="testimonals/index.php">The Work We Do</a></h2>
<h2><a href="../contact/index_personal_injury.php?sid=pi_general_enquiries">Make an Enquiry</a></h2>
<h2><a href="../personnel/index.php">Personnel</a></h2>
<!-- InstanceEndEditable -->
<p>Personal Injury News...</p>
<?php include('../includes/pi_breakingnews.php'); ?>
<div class="roundedBoxBottom"> </div>
<div class="clear"></div>
</div>
<div id="standardcomplaincelogos"> <img src="../images/valid/valid-xhtml10.gif" title="This website meets W3C Standard Complaince" alt="W3C XHTML Valid" width="88" height="31" /><br />
<img src="../images/valid/wcag1AAA.gif" alt="Web Content Accessibility Guidelines Priority 1,2 and 3" width="82" height="31" title="This website meets W3C Web Content Accessibility Guidelines" /><br />
<img src="../images/valid/vcss.gif" alt="" width="88" height="31" title="This website meets W3C Standard Complaince" />
</div>
</div>
<!-- InstanceBeginEditable name="EditRegion7" -->
<div id="rightcol">
<div id="fia">
<h1><strong>No Win No Fee </strong></h1>
<p><strong>100% Compensation</strong></p>
<p>Call Personal Injury on </p>
<h2><strong>0870 609 3630</strong></h2>
<h3>or Email by <a href="../contact/index_personal_injury.php?sid=pi_general_enquiries" title="contact Personal Injury department"><strong>Clicking Here</strong></a></h3>
</div>
<div id="productwhite">
<h1><strong>Advice and support following a road accident</strong></h1>
<p><a href="service.php?sid=Road_traffic_accidents" title="Road Traffic Accident information"><strong>Click Here</strong></a> or call</p>
<h2><strong>0870 609 3630</strong></h2>
</div>
<div id="productcolour">
<h1>Feel you are suffering due to medical negligence?</h1>
<h2><a href="service.php?sid=Medical_negligence" title="Medical Negligence information"><strong>Click Here</strong></a> or call</h2>
<h3>0870 609 3630</h3>
</div>
</div>
<!-- InstanceEndEditable -->
<div id="mainContent">
<!-- InstanceBeginEditable name="EditRegion6" --><h1>What is my claim worth?</h1>
</b>
This is one of the questions at the forefront of many clients’ minds when they first enquire about pursing a personal injury claim. To help answer this question Ashton Morton Slack have created this interactive compensation guide that will help you understand how much you may receive if your claim is successful. <br />
<br />
Ashton Morton Slack even offer a free initial consultation with our nationally renowned team of solicitors to help you understand what is involved in making a claim and to talk in confidence about your situation. <br />
<br />
Simply answer the questions below and follow the step-by-step instructions.
<p><strong>Step One</strong></p>
<p>First please select the area where the injur occured:</p>
<?
///////// Getting the data from Mysql table for first list box//////////
mysql_select_db($database_dbConn, $dbConn);
$query_injuries = "select main_name from injuries";
$injuries = mysql_query($query_injuries, $dbConn) or die(mysql_error());
///////////// End of query for first list box////////////
/////// for second drop down list we will check if category is selected else we will display all the subcategory/////
$id = $_GET['main_name'];
//if(isset($id) and strlen($id) > 0){
mysql_select_db($database_dbConn, $dbConn);
$query_type_injuries = "SELECT * from type_of_injuries where main_name = '$id'";
//}else{$query_type_injuries = "SELECT sub_name from type_of_injuries"; }
$type_injuries = mysql_query($query_type_injuries, $dbConn) or die(mysql_error());
////////// end of query for second subcategory drop down list box ///////////////////////////
$subid = $_GET['sub_name'];
//if(isset($id) and strlen($id) > 0){
mysql_select_db($database_dbConn, $dbConn);
$query_sub_type_injuries = "SELECT * from type_of_injuries where sub_name = '$subid'";
//}else{$query_type_injuries = "SELECT sub_name from type_of_injuries"; }
$sub_type_injuries = mysql_query($query_sub_type_injuries, $dbConn) or die(mysql_error());
echo "<form method='post' name='f1' action='test.php'>";
/// Add your form processing page address to action in above line. Example action=dd-check.php////
////////// Starting of first drop downlist /////////
echo "<select name='main_name' onchange=\"reload(this.form)\"><option value=''>Please Select Injury Area</option>";
while($noticia2 = mysql_fetch_array($injuries)) {
if($noticia2['main_name']==@$id){echo "<option selected value='$noticia2[main_name]'>$noticia2[main_name]</option>"."<BR>";}
else{echo "<option value='$noticia2[main_name]'>$noticia2[main_name]</option>";}
}
echo "</select>";
echo "<br />";
echo "<br />";
////////////////// This will end the first drop down list ///////////
////////// Starting of second drop downlist /////////
echo " <p><strong>Step Two</strong></p>";
echo "<p>Text to go here</p>";
echo "<select name='sub_name'><option value=''>Select Sub Area</option>";
while($noticia = mysql_fetch_array($type_injuries)) {
echo "<option value='$noticia[sub_name]'>$noticia[sub_name]</option>";
}
echo "</select>";
////////////////// This will end the second drop down list ///////////
//// Add your other form fields as needed here/////
echo "<br />";
echo "<br />";
echo " <p><strong>Step Three</strong></p>";
echo "<p>Please enter your contact details.</p>";
if ($message != " ") {
print '<span class="errortext">'.$message.'</span><br /><br />';
} else print '(*) Indicates that these fields must be entered.<br /><br />';
?>
<table height="390" cellpadding="2" cellspacing="2">
<tr>
<td width="161">Name</td><td width="207"><input name="name" type="text" size="30" value="<? if ($message !=" ") { print $name; } ?>" /> <span class="<? print $emailclass; ?>"><? print $star; ?></span></td>
</tr>
<tr>
<td width="161">Email</td><td width="207"><input name="email" type="text" size="30" value="<? if ($message !=" ") { print $email; } ?>" /> <span class="<? print $emailclass; ?>"><? print $star; ?></span></td>
</tr>
<tr>
<td width="161">Telephone</td><td width="207"><input name="telephone" type="text" size="30" value="<? if ($message !=" ") { print $telephone; } ?>" maxlength="11" /> <span class="<? print $emailclass; ?>"><? print $star; ?></span></td>
</tr>
<tr>
<td width="161">Address</td><td width="207"><textarea name="address" cols="30" rows="5" id="address"><? if ($message !=" ") { print $address; } ?></textarea></td>
</tr>
<tr><td colspan="2"><input type="submit" value="Send" /><input type="hidden" name="sent" value="1" /></td></tr>
</table>
<?
echo "</form>";
?>
<!-- InstanceEndEditable -->
</div>
<div style="clear:both"></div>
<div id="copyright">
Copyright © Ashton Morton Slack 2005
<br />
<a href="../disclaimer/index.php">Disclaimer</a> | <a href="../contact/index.php?sid=21">Suggestions</a>
| <a href="http://www.rocketss.com/" title="website design and build by Rocket Science">Site by Rocket Science </a></div>
</div>
</body>
<!-- InstanceEnd --></html>