Hello I would like to know how I can occupy the values that I give to an input of type number in this case in an html and occupy them in a function of a php file, I clarify that in that php file there are several functions .
Hello I would like to know how I can occupy the values that I give to an input of type number in this case in an html and occupy them in a function of a php file, I clarify that in that php file there are several functions .
The ideal would be to know if it is a form and you want to do it from the submit
of your button or, you would like to send them by ajax
.
In the first case you have two options using method GET
and method POST
<form action="tu_archivo.php" method="post">
Nombre usuario: <input type="text" name="username" /><br />
Email: <input type="text" name="email" /><br />
<input type="submit" name="submit" value="¡Enviarme!" />
</form>
The tag action
goes the path of your php file, as you mention that in that same file there are several functions would be something like this from PHP:
<?php
$action = '';
if (isset($_POST['action'])) {
$action = $_POST['action'];
switch ($action) {
case 'login' :
login();
break;
case 'register' :
register();
break;
....
}
}
?>
Thus, you get the action that is called and you can call your function without any problem and from the function access the values:
function login() {
$user = $_POST['username'];
}
In the second case, you can use ajax
and you should include jquery
to your project.
$.ajax({
url: "tu_archivo.php",
type : "POST",
data: { username : 'test', 'action' : 'login' },
...
});
Working in the same way.
What you should do is direct with types of methods that exist:
Example of only 2
<form action="registrar.php" method ="post">
<form action="registrar.php" method ="get">
Depending on what you want to do,
Your question is very basic, I hope this helps you
<form method="post" action="PAGINA A LA QUE QUERES MANDAR LOS DATOS">
// VARIABLE 1 //
<div class="form-group">
<label>NOMBRE DE LA VARIABLE</label>
<input type="TEXT, NUMBER, EL QUE NECESITES" class="form-control"
name="NOMBRE DE LA VARIABLE">
</div>
// VARIABLE 2 //
<div class="form-group">
<label>NOMBRE DE LA VARIABLE</label>
<input type="TEXT, NUMBER, EL QUE NECESITES" class="form-control" name="NOMBRE DE LA VARIABLE">
</div>
// VARIABLE 3, ETC //
// CON UN BOTON TIPO SUBMIT ENVIAS LOS DATOS A LA OTRA PAGINA //
<button type="submit" class="btn btn-default">ENVIAR</button>
</form>
And on the other page, the screenshots:
<?php
$VARIABLE1 = $_POST['NOMBRE DE LA VARIABLE 1'];
$VARIABLE2 = $_POST['NOMBRE DE LA VARIABLE 2'];
$VARIABLE3 = $_POST['NOMBRE DE LA VARIABLE 3 ETC'];
// Y USAS LAS VARIABLES $VARIABLE1, $VARIABLE2, $VARIABLE3 DONDE NECESITES //
?>
You have to recover them in the destination PHP page, through the variables:
<name
>] <name
>] depending on the method you use in the form header (method = 'POST' / 'GET').
<name>
, is the same attribute that you used when creating the form objects to which you refer.