HTML HTML Forms Inputs

Why do i get a 405 Not Allowed error message when using 'action' in html?

I'm learning forms in the html course. There is an "action" command, that when i put in a destination for the action, i get a 405 Not Allowed message.

here is the code:

 <body>

    <form action="#" method="POST" name="my_form">

   </body>

When I replace the # with a url as Nick says would be the normal case to do, instead of getting my destination page, i get the 405 notice.

e.g.:

<body>

  <form action="another_page.html" method="POST" name="my_form">

</body>

If I use the following url "http://another_page.html" in an attempt to get to my 'another_page.html', i get instead a Yahoo search page

I'm working on the workspace, index.html & another_page.html are both at the same level of the directory tree, but this is the first time Nick has used the "action" command so I might be missing something.

I think I should end up on another_page.html when clicking on "continue" on the form we're making in workspace.

4 Answers

john Telep
john Telep
3,239 Points

The action attribute submits information to the server and is processed in the back end code which is handled by php or another programming language the front end code is just directing the destination. Hope that helps.

So without something configured and set up to receive and read the information the 405 error message will display.

Hope that helps

Oh, so it doesn't matter if I enter an actual URL, without a server & it's configuration or back-end software, all I'll get is a 405 error?

john Telep
john Telep
3,239 Points

Yes that is correct.

thank you both for your help!

Adama Sy
Adama Sy
7,076 Points

after the action is complete, whatever have to happe let's say if it was to submit aform, the reste have to be completed with aother language like php, to register the user or ruby or python. but like me you have ot reached that side yet, so this is why you are having that 405 ....

Joan Valls de Padrines Amengual
Joan Valls de Padrines Amengual
10,926 Points

I'm sorry but that is not correct. You can submit a form to the same HTML (or another one) without any server-side processing. Just for example, you can submit a form to the same HTML document (action="" or just without the attribute action) to process the data with Javascript on the client side.

This is why the submission of the form to the same or another HTML document without server-side processing is NOT the cause of the 405 error. The cause of the error is, I think, the method used. I don't know why, but the 405 error is a "Method not allowed" error, so try to change it to GET.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Testing Form submission</title>
</head>
<body>
    <form action="" method="get">
        <input type="text" name="input1">
        <input type="submit">
    </form>
</body>
</html>

This form is fully functional, just for testing, and it submits to the same HTML document where it is.

Hope it helps.

john Telep
john Telep
3,239 Points

you can also set it up to email the response to a selected email address as well without needing to code anything in the "backend".

I am not a 100% sure about the error code and what it means, However i think the point of his question was why it was not doing anything with the form in the first place and why he was getting the 405 error message.

Joan Valls de Padrines Amengual
Joan Valls de Padrines Amengual
10,926 Points

405 Method Not Allowed A request was made of a resource using a request method not supported by that resource; for example, using GET on a form which requires data to be presented via POST, or using PUT on a read-only resource.

Wikipedia HTTP Status Codes