0

So a typical HTML form with a get would look like this :

<form action="https://mywebsite.com/mypage" method="get">
  <input type="text" id="myparam" name="myparam">
  <input type="submit" value="Submit">
</form>

and takes the user to : https://mywebsite.com/mypage?myparam=value

However, I would like to know if it is possible for my form to take my user to : https://mywebsite.com/mypage/value ? Basically, adding the myparam input's value to the path at the end of the url.

Thanks in advance !

1
  • I guess I could write a JavaScript function that redirects the user based on what is in the input, but that doesn't seem like the best way to do it, is it? Commented Jul 21, 2021 at 15:41

1 Answer 1

1

You can create javascript function or you can declare a backend function, and return a redirect to your request route

document.querySelector('form').addEventListener("submit", function (e) {
    e.preventDefault()
    
    let param = document.querySelector('input[name="myparam"]').value

    window.location.href = 'https://mywebsite.com/mypage/' + param
})

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, that's what I ended up doing. Is there no solution to do it in a form?
Another one you can write htaccess or nginx rewrite rule but you can't do that with form

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.