It is. Using the action
attribute of a form you define which URL the form data will be sent to. That is, when the form is submitted, the browser will be responsible for generating another HTTP request for the URL in action
, using the method defined in method
; if method="GET"
, a GET request will be made and, if method="POST"
, a POST request will be made. Since the purpose is to send information to a resource on the server, it makes more sense to use the POST method.
<form action="cadastrar.php" method="POST">
<input type="text" name="name">
<button type="submit">Cadastrar</button>
</form>
For the above example, by pressing the Register button, the form will be submitted, thus generating a POST request to cadastrar.php
, by executing it. In the PHP code, the value entered in the field will be available in the superglobal $_POST
:
$name = $_POST["name"];
If you're doing something similar to this, yes, it's doing it right.