-2
Hello!
I am making use of a FIPE table API, using Javascript to get the data and passing to my database via PHP post. The point is that when passing to PHP, it is not sending the field name but the API code. Where am I wrong? Can you help me please?
- Javascript.
$(document).ready(function() {
var urlBase = "//fipe.parallelum.com.br/api/v1/carros/marcas";
/** Marcas**/
$.getJSON(urlBase, function(data) {
var items = ["<option value=\"\">ESCOLHA UMA MARCA</option>"];
$.each(data, function(key, val) {
items += ("<option value='" + val.codigo + "'>" + val.nome + "</option>");
});
$("#marcas").html(items);
});
/** Veiculo**/
$("#marcas").change(function() {
$.getJSON(urlBase + "/" + jQuery("#marcas").val() + "/" + "modelos", function(data) {
var items = ["<option value=\"\">ESCOLHA UM VEICULO</option>"];
$.each(data.modelos, function(key, val) {
items += ("<option value='" + val.codigo + "'>" + val.nome + "</option>");
});
$("#modelos").html(items);
});
});
/** Ano**/
$("#modelos").change(function() {
$.getJSON(urlBase + "/" + jQuery("#marcas").val() + "/" + "modelos" + "/" + jQuery("#modelos").val() + "/" + "anos", function(data) {
var items = ["<option value=\"\">ESCOLHA O ANO</option>"];
$.each(data, function(key, val) {
//console.log(data)
items += ("<option value='" + val.codigo + "'>" + val.nome + "</option>");
});
$("#ano").html(items);
});
});
});
- register.php.
<div class="col-lg-3 form-group">
<span>Marca</span>
<div class="form-select">
<select name="brand" id="marcas" class="form-control" style="height: 42px;">
</select>
<span class="select-icon"><i class="zmdi zmdi-chevron-down"></i></span>
</div>
</div>
<div class="col-lg-3 form-group">
<span>Modelo</span>
<div class="form-select">
<select name="model" id="modelos" class="form-control"
style="height: 42px;">
</select>
<span class="select-icon"><i class="zmdi zmdi-chevron-down"></i></span>
</div>
</div>
<div class="col-lg-2 form-group">
<span>Ano</span>
<div class="form-select">
<select name="year" id="ano" class="form-control" style="height: 42px;">
</select>
<span class="select-icon"><i class="zmdi zmdi-chevron-down"></i></span>
</div>
</div>
- post.php(Receiving the information).
$placa = test_input($_POST["placa"]);
$marca = test_input($_POST["brand"]);
$modelo = test_input($_POST["model"]);
$ano = test_input($_POST["year"]);
- On the / page at the base.
I honestly didn’t understand your problem. I could illustrate it better?
– Guerra
@Clear War... In item 4, on my registration page, in the tag field for example, I get my javascript return as text (My brand name), but when I go to my PHP that will send it to the database, it passes the "Code" of the brand and not the "Name" that is in the field, as shown in the last image of the database showing only the code.
– JohnSan