1
I am trying to receive data from a form, where some fields use Ajax more specifically the plugin X-Editable
.
When receiving in my PHP page appears the error message below.
HTML:
<form class="form-horizontal" id="termo8" action="procTermo.php" method="POST" target="_blank">
<div class="panel-group">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">
<a data-toggle="collapse" href="#capaTermo8">08. Termo Abertura</a>
</h3>
</div>
<div id="capaTermo8" class="panel-collapse collapse">
<div class="panel-body">
<div class="form-group">
<label class="col-xs-3 control-label">Serial:</label>
<div class="col-xs-3">
<input type="text" class="form-control" name="SerialTermo8" required/>
</div>
</div>
<div class="form-group">
<div class="well text-justify well-sm">
Aos <a href='#' id='diaTermo8'>28</a> dias do mês de <a href='#' id='mesTermo8'>Setembro</a> de <a href='#' id='anoTermo8'>2015</a>,
nesta cidade de <a href='#' id='cidadeTermo8'>CIDADE</a> – <a href='#' id='estadoTermo8'>UF</a>, realizo a abertura deste edital.
</div>
</div>
<div class="cleanfix"></div>
<button class="btn btn-inverse" name="btnGerar" value="gerar8">Gerar <span class="glyphicon glyphicon-save"></span></button>
</div>
</div>
</div>
</div>
</form>
How X-Editable works, when I click on any of these links it opens a Popover so I can edit the data that is already pre-set between <a>
, when finishing click OK ai replaces the value.
Ajax (X-Editable):
<script type="text/javascript">
$(document).ready(function() {
$.fn.editable.defaults.send = "always";
$.fn.editable.defaults.url = "procTermo.php";
$.fn.editable.defaults.ajaxOptions = {type: "POST"};
$('#diaTermo8').editable({type:'text',title: 'Informe o dia'});
$('#mesTermo8').editable({type:'text',title: 'Informe o mes'});
$('#anoTermo8').editable({type:'text',title: 'Informe o ano'});
$('#cidadeTermo8').editable({type:'text',title: 'Informe a Cidade'});
$('#estadoTermo8').editable({type:'text',title: 'Informe o estado'});
});</script>
PHP (procTermo.php):
switch ($_POST['btnGerar']) {
case 'gerar8':
$varMesTermo8 = $_POST['mesTermo8'];
$varDiaTermo8 = $_POST['diaTermo8'];
$varAnoTermo8 = $_POST['anoTermo8'];
$varCidadeTermo8 = $_POST['cidadeTermo8'];
$varEstadoTermo8 = $_POST['estadoTermo8'];
break;
}
When I give echo
in any of these variables, returns the error below.
Error:
Notice: Undefined index: mesTermo8, diaTermo8 (All same error) in /var/www/system/procTermo.php
And in the print_r($_POST)
, does not carry any data.
Hey, Edilson, great explanation. However even with the examples mentioned above, I did not get any value in my $_POST array, as little as I understand, it seems that when I give Ubmit in my form, all other values are sent, but only what this in Ajax does not send, this checking with print_r($_POST)
– lkzvieira
Edit your question, and add more detail to your script, or complete it, so I can see how it is, or store it in Pastebin.
– Edilson
See if it’s clearer Edilson.
– lkzvieira
There it is, an example to aid the explanation.
– Edilson