It is. Through the attribute action
of a form you define what will be the URL to which the form data will be sent. That is, when the form is submitted, the browser takes care of generating another HTTP request for the URL at 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. As the goal 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 example above, by pressing the button Register, the form will be submitted, thus generating a POST request to cadastrar.php
, running it. In PHP code, the value entered in the field will be available in superglobal $_POST
:
$name = $_POST["name"];
If you’re doing something like this, yes, you’re doing it right.
You want to send the data the traditional way (that reloads the page) or by ajax?
– bfavaretto
I want to send in the traditional way, but my PHP page has a paragraph, just so I know if it was sent to the bank or not, nor do I use ajax.
– Diogo dgo