Forum Moderators: open

Message Too Old, No Replies

Form query issue

         

futureX

5:18 pm on Mar 3, 2007 (gmt 0)

10+ Year Member



I'm having a little problem finding a solution to this one, searching turns up random results (correct me if i'm just typing the wrong stuff);

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]

rocknbil

8:52 pm on Mar 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may have it backwards. I use mod_rewrite to take /n and direct it to?query=n&amount=0&x=0&y=1&id=1. I'm guessing you may have meant this anyway.

What is your form method? Try <form method="post">? Without a method specified it will resort to the default, get, which can result in a query string.

futureX

8:53 am on Mar 4, 2007 (gmt 0)

10+ Year Member



Hi, yes I did mean the rewrite was the other way round... I just always think of them the wrong way round (which is probably why it gets me confused).

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]

rocknbil

10:19 am on Mar 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



futurex - why do you need to resort to Javascript for this? The problem with that is that if Javascript is disabled it's going to post back to "itself," that is, whatever page this is on it's just going to act like a page refresh.

<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.

vivek

9:10 am on Mar 9, 2007 (gmt 0)

10+ Year Member



hi,
some one please help me for getting feed back from my site , need the full code for collect feed back from my site through mail, need to creat a form with (NAME , EMAIL , COUNTRY , ADDRESS , FEEDBACK ,) & a sumit buttom . I tryed it from last 2 days but I failed . pleaze .

Thank you