I have this form for processing..
<form action="driver.php" method="GET">
<input type="text" placeholder="Search" id="search" name="n">
<button type="submit">Submit</button>
</form>
by default the url is .php?n=typedname
so i did modifications in .htaccess and convert it to for SEO friendly urls modrewrite issue - 404 error thanks to anubhava
everything is well, but the problem now es when I type and click the submit button, it will go to .php?n=typedname
so how can I make it to go this url instead after clicking submit?
I think javascript can do this, so i tagged it, hope im not wrong.
thanks.
I have this form for processing..
<form action="driver.php" method="GET">
<input type="text" placeholder="Search" id="search" name="n">
<button type="submit">Submit</button>
</form>
by default the url is http://sites./driver.php?n=typedname
so i did modifications in .htaccess and convert it to http://sites./driver/typedname
for SEO friendly urls modrewrite issue - 404 error thanks to anubhava
everything is well, but the problem now es when I type and click the submit button, it will go to http://sites./driver.php?n=typedname
so how can I make it to go this url http://sites./driver/typedname
instead after clicking submit?
I think javascript can do this, so i tagged it, hope im not wrong.
thanks.
Share Improve this question edited May 23, 2017 at 12:32 CommunityBot 11 silver badge asked Dec 10, 2014 at 20:11 OverflowOverflow 872 silver badges7 bronze badges 4- 1 I am confused with what you are trying to do exactly? You're trying to go this new page after submit? Change your action URL? – cport1 Commented Dec 10, 2014 at 20:14
- so now whether you type it sites./driver/typedname or sites./driver.php?n=typedname it works ? – Yehia Awad Commented Dec 10, 2014 at 20:15
- No, this is nothing that javascript should do. Instead, make your webserver transparently redirect clients to the url with the slash. – Bergi Commented Dec 10, 2014 at 20:15
- cport I don't mean exactly to go to that url, I have just used it as an example.. it all depends what the user inputs. so whatever the user inputs and he/she clicks submit, I want it to go sites./driver/userinput – Overflow Commented Dec 10, 2014 at 20:20
2 Answers
Reset to default 5You will have to handle form submit event yourself. Something like this:
document.querySelector('form').addEventListener('submit', function(e) {
e.preventDefault();
location.href = '/driver/' + this.elements.n.value;
}, false);
jQuery
$('button[type=submit]').click(function(e){
e.preventDefault();
e.stopPropagation();
window.location = "http://sites./driver/" + $('#search').val();
return false;
});
or
$('form').submit(function(e) { // you really need to class/ID your form
// all that code
});
Now this is quick and dirty to give you the idea. You'd of course want to sanitize your input (good idea to do that on the front-end as well as the back-end).