Form send JS to a PHP

1

Currently I have developed an HTML form and validated the same with JS, I am now wanting to send this data to a MYSQL database, however I am using in the ACTION of the form the address of a page in PHP, which contains the entire structure to insert in the bank.

Now my doubt and how to integrate these languages and if this is correct what I did?

    
asked by anonymous 26.09.2017 / 23:55

1 answer

1

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.

    
27.09.2017 / 00:10