سؤال

<form action="/foo">
        <input type="text" name="q">
        <input type="submit" >
</form>

In the previous HTML, if the user types in 'bar' and clicks the button it would submit to example.com/foo?q=bar. How can I make it go to example.com/foo/bar? I can easily do it with JS but I'm trying to stick to HTML.

هل كانت مفيدة؟

المحلول

There is no way to do this in HTML, you need a programming language.

Have something on the server process the form an issue an HTTP 301 response with a Location header.

You could enhance that by use the form's submit event to prevent the default action and set location in JS.

نصائح أخرى

You cannot change the value of the action attribute with HTML only. You need to use JS or any other scripting language.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top