Forum Moderators: open
I have a search form on my site which queries the CMS i use.
I have mod rewrites in place which basically change;
http://example.com/?query=n&amount=0&x=0&y=1&id=1
to
http://example.com/search/n
what i want to do is have a html form output the rewritten, friendly url instead of the original. But even if I alter the form the query still begins qith a '?'.
any help would be appreciated.
[edited by: engine at 9:05 am (utc) on Mar. 4, 2007]
[edit reason] examplified [/edit]
Thanks for the info on the post method, that has allowed me to look into a bit of javascript altering the post method... I use the following code and it works fine;
<form name="searchform" onSubmit="document.searchform.method='post'; document.searchform.action='/search/' + document.searchform.query.value ;">
<input name="query" class="formfield" maxlength="60" value="">
<input type="submit" value="Search" />
</form>
[edited by: futureX at 9:16 am (utc) on Mar. 4, 2007]
<form name="searchform" method="post" action="/search/">
<input name="query" class="formfield" maxlength="60" value="">
<input type="submit" value="Search" />
</form>
This will still submit the values for query to /search/. If you want to use Javascript to validate "query",
<form name="searchform" method="post" action="/search/">
<input name="query" id="query" class="formfield" maxlength="60" value="">
<input type="submit" onClick="return checkQ(this.form);" value="Search" />
</form>
<script type="text/javascript">
function checkQ(form) {
if (form.query.value == '') {
alert('Enter a query.');
return false;
}
else { form.submit(); }
}
</script>
What's happening: If javascript is disabled, the call to the Javascript routine is ignored and the form submits as expected. However, if Javascript is enabled and query is blank, the user is immediatley notified by an alert and return false immediately following the alert causes the form to NOT submit. If there's a value in query, form.submit() causes the form object to submit.
So it works with or without Javascript, this is important.