It starts with some errors and faults in your html, the error is that it does not close the <label>
tags and I assume you want to send the information with the% http POST
method, which is defined in the <form>
tag and the action that is the php
script that will process server-side information.
<form id="form-carro" method="POST" action="script.php"> <!-- AJUSTAR AQUI O NOME DO FICHEIRO PHP -->
<label class="margem-direita" style="margin-right: 5%" for='seguro-novo'>
<input id='seguro-novo' type="radio" name="seguro" value="Seguro Novo">Seguro Novo</label>
</label>
<label class="margem-direita" style="margin-right: 5%" for='renovacao'>
<input id='renovacao' type="radio" name="seguro" value="Renovação">Renovação</label>
</label>
<label class="margem-direita" for='sinistrado'>
<input id='sinistrado' type="radio" name="seguro" value="Sinistrado">Sinistrado</label>
</label>
<input type="submit" value="enviar">
</form>
In script.php (this can have whatever name you want):
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['seguro'])) {
echo $_POST['seguro'];
}
}
Note that if you want the data to be processed on the same page / file of the form simply do not set the action on <form>
:
<form id="form-carro" method="POST">
And include the php that's up on the same page.
EDITION (I noticed the comments in the question you are asking with ajax):
I made a small but complete example, you can test it by putting it all in the same .php file (as it is) on the server, or you can put the php part in another file and set the correct url in the ajax request:
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(isset($_POST['seguro'])) {
echo $_POST['seguro'];
}
die();
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script><formid="form-carro" method="POST">
<label class="margem-direita" style="margin-right: 5%" for='seguro-novo'>
<input id='seguro-novo' type="radio" name="seguro" value="Seguro Novo">Seguro Novo</label>
</label>
<label class="margem-direita" style="margin-right: 5%" for='renovacao'>
<input id='renovacao' type="radio" name="seguro" value="Renovação">Renovação</label>
</label>
<label class="margem-direita" for='sinistrado'>
<input id='sinistrado' type="radio" name="seguro" value="Sinistrado">Sinistrado</label>
</label>
<input type="submit" value="enviar">
</form>
<script>
$('input[type="submit"]').on('click', function(e) {
e.preventDefault();
var seg = $('input[name="seguro"]:checked').val();
$.ajax({
url: '',
type: 'POST',
data: {seguro: seg},
success: function (response) {
// aqui coloca tudo o que quer que aconteça caso a requisição seja bem sucedida
// trabalha os dados que vieram do servidor como quiser
alert('escolheu: ' +response);
},
error: function(xhr, status, error){
console.log("Fail: " + xhr.responseText);
}
});
return false;
});
</script>