Here's what my diretory tree looks like
/application
/lib
/util
/login
/views
/base_view
My login page is
localhost:737/astuto-lena/branches/application/views/base_view/index.php
And I want the action of my form to be this
localhost:737/astuto-lena/branches/application/util/login/main.php
Here's my form declaration
<form class="form_login" action="./util/login/main.php" method="POST">
...
</form>
But when I click the submit button, it takes me to
localhost:737/astuto-lena/branches/application/views/base_view/util/login/main.php
Which is the wrong path and generates a Error 404.
So what's wrong with the way I'm using relative paths in my form declaration and how can I fix that?
No, a form has only one action.
PHP $_POST is a PHP super global variable which is used to collect form data after submitting an HTML form with method="post". $_POST is also widely used to pass variables.
The action attribute defines the action to be performed when the form is submitted. Usually, the form data is sent to a file on the server when the user clicks on the submit button. In the example below, the form data is sent to a file called "action_page.php".
In order to stay on the same page on submit you can leave action empty ( action="" ) into the form tag, or leave it out altogether. For the message, create a variable ( $message = "Success! You entered: ". $input;" ) and then echo the variable at the place in the page where you want the message to appear with <?
In your relative path ./util/login/main.php
, you're using ./
which refers to the current folder, so it assumes that the folder structure /util/login
is inside /base_view
. You should try using ../
which refers to the parent folder:
<form class="form_login" action="../../util/login/main.php" method="POST">
...
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With