So I have written this code for a form (search form) and it looks like this:
<form action="" method="get">
<select >
<option value="name">Client Name:</option>
<option value="email">Client Email:</option>
<option value="tnx_id">Transaction ID:</option>
<option value="amount">Amount:</option>
</select>
<input type="text" name="svalue" placeholder="Search"></input>
<input type="image" name="submit" src="img/search_btn.png"></input>
</form>
When user clicks Search I want the url to be formatted this way:
http://localhost/pp/index.php?search&name=haha
But instead I get:
http://localhost/pp/index.php?search=name&svalue=haha&submit.x=0&submit.y=0
I'm only having difficulties formating the url correctly because the rest of the code is good, I cannot get rid of that &submit.x=0&submit.y=0
at the end of the url too. Do you have any ideas guys? Basically my desired url format gets the selected option (name, email, tnx_id, amount) and assigns svalue's value to it.
I'd appreciated your help, Thank you in advance, Thanks.
That is how forms work. Each control gives a name=value pair in the submitted data.
You could hack it with JavaScript, but that becomes fragile. Give the <select>
element a name and change the server side script so that it takes the two pieces of data as separate pieces of data.
I cannot get rid of that
&submit.x=0&submit.y=0
at the end of the url too
Remove the name
attribute from the image map so it won't be a successful control.
<input type="image" src="img/search_btn.png">
Other improvements you should make:
<input>
is an empty element. It should not have an end tag. If you are writing XHTML then use the empty element syntax.placeholder
should not be used as a replacement for <label>
Use JavaScript to create the URL. If you're using jQuery:
var url = 'http://localhost/pp/index.php?search&'
+ encodeURIComponent($('#id-of-your-select-element').val())
+ '='
+ encodeURIComponent($('#id-of-your-svalue-element').val());
Edit: As for getting rid of submit.x
and submit.y
, see @Quentin's answer.
in your php code you can add this:-
if(isset($_GET['name']))
{
$searchString="&cs=".$_GET['name'];
}
then use this:
http://localhost/pp/index.php?".$searchString."/
i think this will help you to get the right thing. if you want to use pagination with that,i have a code for you which i used before and it works great. just try it once!