I'm trying to pass the values of a select multiple pro PHP. I already searched for examples on the internet (my code is just like the examples I saw), but the "echo" command does not show me anything. Can you help me ? Thank you.
$funcao = $_POST['funcao'];
$frutas = $_POST['frutas'];
if($funcao == 'copiar') {
foreach ($frutas as &$item) {
echo "Frutas escolhidas: ".$item."<br>";
}
exit;
}
<form method="post" name="frmfrutas" action="rascunho.php" id="frmfrutas">
<input type="hidden" name="funcao" id="funcao" value=""/>
<select class="slMultiple" multiple="multiple" name="frutas[]" id="frutas" size="10">
<option value="1">Maçã</option>
<option value="2">Banana</option>
<option value="3">Limão</option>
<option value="4">Morango</option>
<option value="5">Uva</option>
<option value="6">Amora</option>
</select>
<input type="button" value="SELECIONAR" class="btn btn-primary" id='btSelecionar' name='btSelecionar'/>
</form>
$(document).on('click', '#btSelecionar', function(event) {
event.preventDefault();
$("#funcao").val("copiar");
var self = $(this);
$.ajax({
url: "/rascunho.php",
type: "POST",
timeout:default_timeout,
data: $("#frmfrutas").serialize(),
beforeSend: function(){
self.attr('disabled', 'true');
},
success: function() {
},
error: function(jqXHR, textStatus){
console.log(textStatus, jqXHR);
},
complete: function(){
self.removeAttr('disabled');
}
});
});