PDA

View Full Version : Stuck with turning cust ref into address to link


scrads
08-31-2006, 08:40 PM
Hi i'm a semi novice and am currently in the process of building a new site, i have a problem where customers would put their ref numbers in and then it would link to their relevant page, this is the code i have so far:
<form action="" method="get" enctype="multipart/form-data" name="formCustom" target="_self">
<input name="CustomerRef" type="text" value="Customer Ref" size="12" maxlength="12">
<input type="submit" value="Submit">
</form>
this is what is returned when data is entered
http://www.scradspace.co.uk/ladies.htm?CustomerRef=12356 the bit in bold is what is generated by the form.
now i want whats put in the text box to appear in the address bar and link to the relevant page, something along the lines of .../CustomerRef=12356.htm. how do i do this?

_Aerospace_Eng_
08-31-2006, 09:16 PM
<?php
if(isset($_POST['go']) && $_POST['go'] = 'Submit') // if submitted
{
$CustomerRef = $_POST['CustomerRef']; // gets CustomerRef input
header('Location: http://www.scradspace.co.uk/CustomerRef='.$CustomerRef.'.htm'); // takes user to correct page on submit when JS is disabled
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function goTo()
{
var CustRef = document.forms['formCustom'].CustomerRef.value; // gets CustomerRef input
window.location = 'http://www.scradspace.co.uk/CustomerRef='+CustRef+'.htm'; // take user to correct page on submit
return false;
}
</script>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" name="formCustom" onsubmit="return goTo()">
<input name="CustomerRef" type="text" value="Customer Ref" size="12" maxlength="12" onfocus="if(this.value == this.defaultValue) this.value = ''" onblur="if(this.value = '') this.value = this.defaultValue">
<input type="submit" name="go" value="Submit">
</form>
</body>
</html>

The one above has a php snippet in it meaning when saved with a .php extension and JS is disabled it will still work as intended. If you don't want to use php then just remove the lines before the doctype.

scrads
08-31-2006, 09:35 PM
thanks alot mate just what i needed. wasnt expecting a response so quickly either.
Cheers