Forum Moderators: open

Message Too Old, No Replies

form action rewrite

navigating via form

         

StevenHill

3:18 am on Jun 1, 2006 (gmt 0)

10+ Year Member



I have a form for entering in one field, a ZIP code, and then when submitted it calls the index.php and passes the ZIP_Code field via GET, which results in a URL that is index.php?ZIP_Code=99999, and this works fine. I have mod_rewrite set up to take a URL like 99999_z_site.html and rewrite it to the index.php?ZIP_Code=99999 but I can not seem to get the form submit to put out the 99999_z_site.html version of the URL. I have tried a number of things. The form name is zipform and I have tried an onsubmit="document.location=document.ZIP_Code + '_z_site.html';" as part of the <FORM ...> tag and a similar thing with onclick as part of the <INPUT ...> tag for the submit button. I have also tried to modify the value of the action attribute without success.

Basically, I am looking for a way to build the URL from the entry made in the FORM.

Any thoughts are greatly appreciated.

Steven Hill
Martin, GA USA

alex77

12:41 pm on Jun 1, 2006 (gmt 0)



Hi!

I'm not sure if I'm getting your problem, why'd you want to have your form submit to a url which is then translated by mod_rewrite to what the form would originally call anyway?

nevertheless, you might try this:


<input type="button" onClick="callZip()" value="submit" />
<script type="text/javascript">
function callZip() {
var zip = document.zipform.ZIP_Code;
var loc = '/' + zip.value + '_z_site.html';
document.location.href = loc;
}
</script>

Hope I could help you along.

StevenHill

1:00 pm on Jun 1, 2006 (gmt 0)

10+ Year Member



I have found a solution and will present it here in hopes it will help someone else.


<p>
<h4>Dealers by<br/>ZIP Code</h4>
<script language="JavaScript">
document.write('<form name="ZipForm">');
</script>
<noscript>
<form action="{$homeLink}/index.php"
name="ZipForm"
method="get">
</noscript>
<input type="text"
name="ZIP_Code"
size="5"
maxlength="5"
value="">
</input>
<script language="JavaScript">
document.write('<input type="button"');
document.write(' onClick = "location.href');
document.write(' = document.ZipForm.ZIP_Code.value + \'_z_site.html\';"');
document.write(' value="Search">');
document.write('</input>');
</script>
<noscript>
<input type="submit"
value="Search">
</input>
</noscript>
</form>
</p>

alex77:: I want the URL to appear in the browser as the 99999_z_site.html because it just looks cleaner than having a URL with variables exposed.

Thanks for the reply though, and I hope that the solution I figured out does help others. Basically, it puts out one type of form if they have scripting turned on and another if they do not. Granted, without scripting I get the ugly URL, but at least in most cases it will appear as I would like it to. Without JavaScript, I would probably have to go through an intermediate php script that would simply take the passed variable and reformat the URL an silently redirect to the new URL. I am not sure I want to go through that.

Steven Hill
Martin, GA USA