Relative URL path in form action not working

Issue

I’m a making a form but clicking on that form’s submit button doesn’t take me to the right path.

<form action="delete" method="post">
    <button type="button">Cancel</button>
    <button type="submit">Delete</button>
</form>

It should take me to http://localhost:5000/<id>/delete
(In place of will be the user ID)

But it takes me to http://localhost:5000/delete

And http://localhost:5000/<id>/delete is a webpage not a file. Which means that this web site is not static, it’s dynamic.

What am I doing wrong here?

Solution

You should try to extract the ID from the URL and then set that ID into your form action like:

follow this stackoverflow question to extract ID from url How can I get query string values in JavaScript?

<form action="/<id>/delete" method="post">
    <button type="button">Cancel</button>
    <button type="submit">Delete</button>
</form>

Answered By – Amit Dagar

Answer Checked By – Marie Seifert (AngularFixing Admin)

Leave a Reply

Your email address will not be published.